{{ v.name }}
{{ v.cls }}类
{{ v.price }} ¥{{ v.price }}
linux网络相关ifdownens33关闭网卡&&ifupens33启动网卡(&&一起执行)
应用场景:当想单独更改某个网卡的信息时,可使用此命令
cd/etc/sysconfig/network-scripts/进入网卡目录cpifcfg-ens33ifcfg-ens33:0拷贝网卡配置文件
vi!$编辑配文件
修改name:ens33:0
device:ens33:0
ipaddr更换ip
删除dns1gateway
修改后关闭,开启网卡。
查看网卡是否连接(linkok表示连接)
[root@g_linux01network-scripts]#mii-toolens33ens33:negotiated1000baset-fdflow-control,linkok
如果mii-toolens33不支持也可用ethtoolens33
[root@g_linux01network-scripts]#ethtoolens33settingsforens33:supportedports:[tp]supportedlinkmodes:10baset/half10baset/full100baset/half100baset/full1000baset/fullsupportedpauseframeuse:nosupportsauto-negotiation:yesadvertisedlinkmodes:10baset/half10baset/full100baset/half100baset/full1000baset/fulladvertisedpauseframeuse:noadvertisedauto-negotiation:yesspeed:1000mb/sduplex:fullport:twistedpairphyad:0transceiver:internalauto-negotiation:onmdi-x:off(auto)supportswake-on:dwake-on:dcurrentmessagelevel:0x00000007(7)drvprobelinklinkdetected:yes更改主机名
hostnamectlset-hostname[主机名](centos7的命令)
配置文件在/etc/hostname
/etc/resolv.conf(可临时更改,想永久更改要在网卡配置文件中改)
etc/hosts更改本机域名解析
以先出现的记录为主。这个文件也是从上到下依次执行的,127.0.0.1是特例,本机ip优先级高
修改配置文件中selinux=disabled
getenforce可查询selinux是否开启
可能返回结果有三种:enforcing、permissive和disabled。disabled代表selinux被禁用,permissive代表仅记录安全警告但不阻止可疑行为,enforcing代表记录警告且阻止可疑行为。
centos7默认开启firewalld关闭netfilter,netfilter是centos6的防火墙。但7依然可以用
关闭firewalld流程
开启netfilter
filter,nat,mangle,raw,默认表是filter(没有指定表的时候就是filter表)。
filter:一般的过滤功能
nat:用于nat功能(端口映射,地址映射等)
mangle:用于对特定数据包的修改
raw:优先级最高,设置raw时一般是为了不再让iptables做数据包的链接跟踪处理,提高性能
数据报从进入系统,进行ip校验以后,首先经过第一个hook函数nf_ip_pre_routing进行处理;然后就进入路由代码,其决定该数据报是需要转发还是发给本机的;若该数据报是发被本机的,则该数据经过hook函数nf_ip_local_in处理以后然后传递给上层协议;若该数据报应该被转发则它被nf_ip_forward处理;经过转发的数据报经过最后一个hook函数nf_ip_post_routing处理以后,再传输到网络上。本地产生的数据经过hook函数nf_ip_local_out处理后,进行路由选择处理,然后经过nf_ip_post_routing处理后发送出去。iptables语法
案例:http://blog.chinaunix.net/uid-9950859-id-98279.html
查看默认规则
[root@g_linux01~]#iptables-nvlchaininput(policyaccept0packets,0bytes)pktsbytestargetprotoptinoutsourcedestination116k28macceptall--**0.0.0.0/00.0.0.0/0ctstaterelated,established00acceptall--lo*0.0.0.0/00.0.0.0/011342963kinput_directall--**0.0.0.0/00.0.0.0/011342963kinput_zones_sourceall--**0.0.0.0/00.0.0.0/011342963kinput_zonesall--**0.0.0.0/00.0.0.0/000dropall--**0.0.0.0/00.0.0.0/0ctstateinvalid11330963krejectall--**0.0.0.0/00.0.0.0/0reject-withicmp-host-prohibited
重启规则serviceiptabalesrestart(重启后会加载配置文件中的规则)
保存规则serviceiptablessave(修改后不保存,重启后会失效)
规则保存在cat/etc/sysconfig/iptables(如果没有安装yuminstalliptables-services)
iptables-f清空规则
iptables-tfilter-nvl(指定显示哪个表的规则,不加-t默认显示filter)
iptables-tnat-nvl
iptables-z清空计数器
限制某ip登录
iptables-ainput-s192.168.188.1-ptcp--sport1234-d192.168.188.128--dport80-jdorp/reject
增加的规则在最后
-i在规则最前插入
数据包进来后,会优先从前往后匹配规则(一旦匹配到就执行)
显示规则编号iptables-nvl--line-number
[root@g_linux01~]#iptables-nvl--line-numberchaininput(policyaccept0packets,0bytes)numpktsbytestargetprotoptinoutsourcedestination116514676acceptall--**0.0.0.0/00.0.0.0/0staterelated,established200accepticmp--**0.0.0.0/00.0.0.0/0300acceptall--lo*0.0.0.0/00.0.0.0/0400accepttcp--**0.0.0.0/00.0.0.0/0statenewtcpdpt:225837241rejectall--**0.0.0.0/00.0.0.0/0reject-withicmp-host-prohibitedchainforward(policyaccept0packets,0bytes)numpktsbytestargetprotoptinoutsourcedestination100rejectall--**0.0.0.0/00.0.0.0/0reject-withicmp-host-prohibited
删除规则iptables-dinput5
更改默认规则,红框里就是默认规则