本文共 43005 字,大约阅读时间需要 143 分钟。
1 2 | 以太网:ethX,例如:eth0, eth1, ... PPP网络:pppX,例如:ppp0, ppp1, ... |
1 2 3 4 5 | ①如果Fireware或BIOS为主板上集成的设备提供索引信息可用,则根据此索引进行命名,如:eno1, eno2, ... ②如果Fireware或BIOS为PCI-E扩展槽所提供的索引信息可用,且可预测,则根据此索引进行命名,如ens1, ens2, ... ③如果硬件接口的物理位置信息可用,则根据此信息命名,如enp2s0, ... ④如果用户显示定义,也可根据MAC地址命名,例如:enx122161ab212 #上述均不可用时,则仍使用传统方式命名; |
1 2 3 | en:ethernet wl:wlan #无线局域网 ww:wwan #无线广域网 |
1 2 3 4 | o<index> #集成设备的设备索引号; s<slot> #扩展槽对的索引号; x<MAC> #基于MAC地址的命名; p<bus>s<slot> #基于总线及槽的拓扑结构进行命名; |
命令行配置(ifcfg家族,iproute家族,nm家族)
配置文件
文本图形化配置
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | [root@localhost ~] # ifconfig ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 从flags可知该接口已启用,支持广播、组播,mtu值 inet 10.10.10.140 netmask 255.255.255.0 broadcast 10.10.10.255 IPv4地址 子网掩码 广播地址 inet6 fe80::20c:29ff:fec8:ff4e prefixlen 64 scopeid 0x20<link> IPv6地址 掩码长度 作用域,link表示仅该接口有效 ether 00:0c:29:c8:ff:4e txqueuelen 1000 (Ethernet) 网卡接口的MAC地址 传输队列长度 接口类型为Ethernet RX packets 266 bytes 26083 (25.4 KiB) 上行表示此接口接收的报文个数,总字节数 RX errors 0 dropped 0 overruns 0 frame 0 接收报文错误数,丢弃数,溢出数,冲突的帧数 TX packets 141 bytes 20086 (19.6 KiB) 上行表示此接口发送的报文个数,总字节数 TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 发送报文错误数,丢弃数,溢出数,载荷数,冲突数 lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6 ::1 prefixlen 128 scopeid 0x10<host> loop txqueuelen 1 (Local Loopback) RX packets 0 bytes 0 (0.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 0 bytes 0 (0.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | [root@localhost ~] # ifconfig -a ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 10.10.10.140 netmask 255.255.255.0 broadcast 10.10.10.255 inet6 fe80::20c:29ff:fec8:ff4e prefixlen 64 scopeid 0x20<link> ether 00:0c:29:c8:ff:4e txqueuelen 1000 (Ethernet) RX packets 318 bytes 30857 (30.1 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 192 bytes 24612 (24.0 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 ens38: flags=4098<BROADCAST,MULTICAST> mtu 1500 ether 00:0c:29:c8:ff:58 txqueuelen 1000 (Ethernet) RX packets 0 bytes 0 (0.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 0 bytes 0 (0.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6 ::1 prefixlen 128 scopeid 0x10<host> loop txqueuelen 1 (Local Loopback) RX packets 0 bytes 0 (0.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 0 bytes 0 (0.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 |
1 2 3 4 5 6 7 8 9 | [root@localhost ~] # ifconfig ens33 ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 10.10.10.140 netmask 255.255.255.0 broadcast 10.10.10.255 inet6 fe80::20c:29ff:fec8:ff4e prefixlen 64 scopeid 0x20<link> ether 00:0c:29:c8:ff:4e txqueuelen 1000 (Ethernet) RX packets 341 bytes 32973 (32.2 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 214 bytes 28076 (27.4 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 |
1 2 3 4 5 6 7 8 9 10 | [root@localhost ~] # ifconfig ens38 192.168.10.1/24 up [root@localhost ~] # ifconfig ens38 ens38: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 #UP表示已启用 inet 192.168.10.1 netmask 255.255.255.0 broadcast 192.168.10.255 inet6 fe80::20c:29ff:fec8:ff58 prefixlen 64 scopeid 0x20<link> ether 00:0c:29:c8:ff:58 txqueuelen 1000 (Ethernet) RX packets 1 bytes 60 (60.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 8 bytes 648 (648.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 |
1 | [root@localhost ~] # ifconfig ens38 192.168.10.1 netmask 255.255.255.0 up |
1 2 3 4 5 6 7 8 9 10 11 | [root@localhost ~] # ifconfig ens33 promisc [root@localhost ~] # ifconfig ens33 ens33: flags=4419<UP,BROADCAST,RUNNING,PROMISC,MULTICAST> mtu 1500 混杂模式已开启 inet 10.10.10.140 netmask 255.255.255.0 broadcast 10.10.10.255 inet6 fe80::20c:29ff:fec8:ff4e prefixlen 64 scopeid 0x20<link> ether 00:0c:29:c8:ff:4e txqueuelen 1000 (Ethernet) RX packets 762 bytes 71714 (70.0 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 538 bytes 65928 (64.3 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 |
1 2 3 4 5 6 7 8 9 10 | [root@localhost ~] # ifconfig ens33 -promisc [root@localhost ~] # ifconfig ens33 ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 #混杂模式已关闭 inet 10.10.10.140 netmask 255.255.255.0 broadcast 10.10.10.255 inet6 fe80::20c:29ff:fec8:ff4e prefixlen 64 scopeid 0x20<link> ether 00:0c:29:c8:ff:4e txqueuelen 1000 (Ethernet) RX packets 836 bytes 78408 (76.5 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 593 bytes 72218 (70.5 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 |
1 2 3 4 5 | [root@localhost ~] # ifdown ens38 Could not load file '/etc/sysconfig/network-scripts/ifcfg-ens38' Could not load file '/etc/sysconfig/network-scripts/ifcfg-ens38' Could not load file '/etc/sysconfig/network-scripts/ifcfg-ens38' Could not load file '/etc/sysconfig/network-scripts/ifcfg-ens38' |
1 2 3 4 5 6 | [root@localhost ~] # ifup ens38 Could not load file '/etc/sysconfig/network-scripts/ifcfg-ens38' Could not load file '/etc/sysconfig/network-scripts/ifcfg-ens38' Could not load file '/etc/sysconfig/network-scripts/ifcfg-ens38' Could not load file '/etc/sysconfig/network-scripts/ifcfg-ens38' RTNETLINK answers: File exists |
1 2 3 4 5 6 7 | [root@localhost ~] # route Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 10.10.10.0 0.0.0.0 255.255.255.0 U 0 0 0 ens33 link- local 0.0.0.0 255.255.0.0 U 1002 0 0 ens33 192.168.10.0 0.0.0.0 255.255.255.0 U 0 0 0 ens38 default gateway 0.0.0.0 UG 0 0 0 ens33 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | [root@localhost ~] # route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 10.10.10.0 0.0.0.0 255.255.255.0 U 0 0 0 ens33 169.254.0.0 0.0.0.0 255.255.0.0 U 1002 0 0 ens33 192.168.10.0 0.0.0.0 255.255.255.0 U 0 0 0 ens38 0.0.0.0 10.10.10.2 0.0.0.0 UG 0 0 0 ens33 #Destination:目标路由; #Gateway:网关;如果是默认路由的网关则可称为默认网关;其中Gateway为0.0.0.0的路由条目为无需 网关之意,表示该目标路由为本地主机路由,又称直连路由。 #Genmask:子网掩码; #Flags:路由的标志位;U表示启用状态,G表示默认网关,H表示主机路由; #Metric:度量值;表示到达该目标路由的开销; #Iface:使用哪个接口将报文发送出去; |
1 2 3 4 5 6 7 8 | Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 6.6.6.6 192.168.10.1 255.255.255.255 UGH 0 0 0 ens38 #显示已添加; 10.0.0.0 192.168.10.1 255.0.0.0 UG 0 0 0 ens38 10.10.10.0 0.0.0.0 255.255.255.0 U 0 0 0 ens33 169.254.0.0 0.0.0.0 255.255.0.0 U 1002 0 0 ens33 192.168.10.0 0.0.0.0 255.255.255.0 U 0 0 0 ens38 0.0.0.0 10.10.10.2 0.0.0.0 UG 0 0 0 ens33 |
1 2 3 4 5 6 7 8 9 10 11 | [root@localhost ~] # route add -net 10.0.0.0/8 gw 192.168.10.1 #注意:下一跳(网关)必须与本地网络上某个主机IP地址处在同一网段;接口会自动识别,可不指定; [root@localhost ~] # route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 10.0.0.0 192.168.10.1 255.0.0.0 UG 0 0 0 ens38 #显示已添加; 10.10.10.0 0.0.0.0 255.255.255.0 U 0 0 0 ens33 169.254.0.0 0.0.0.0 255.255.0.0 U 1002 0 0 ens33 192.168.10.0 0.0.0.0 255.255.255.0 U 0 0 0 ens38 0.0.0.0 10.10.10.2 0.0.0.0 UG 0 0 0 ens33 |
1 2 3 4 5 | 方式一: [root@localhost ~] # route add -net 0.0.0.0/0 gw 10.10.10.2 方式二: [root@localhost ~] # route add default gw 10.10.10.2 |
1 2 3 4 5 6 7 8 | [root@localhost ~] # route del -net 10.0.0.0/8 [root@localhost ~] # route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 10.10.10.0 0.0.0.0 255.255.255.0 U 0 0 0 ens33 169.254.0.0 0.0.0.0 255.255.0.0 U 1002 0 0 ens33 192.168.10.0 0.0.0.0 255.255.255.0 U 0 0 0 ens38 0.0.0.0 10.10.10.2 0.0.0.0 UG 0 0 0 ens33 |
1 2 3 4 5 6 7 8 9 10 11 12 | 方式一: [root@localhost ~] # route del default [root@localhost ~] # route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 10.10.10.0 0.0.0.0 255.255.255.0 U 0 0 0 ens33 169.254.0.0 0.0.0.0 255.255.0.0 U 1002 0 0 ens33 192.168.10.0 0.0.0.0 255.255.255.0 U 0 0 0 ens38 #默认路由已删除; 方式二: [root@localhost ~] # route del -net 0.0.0.0/0 |
1 2 3 4 5 6 7 | [root@localhost ~] # netstat -rn Kernel IP routing table Destination Gateway Genmask Flags MSS Window irtt Iface 10.10.10.0 0.0.0.0 255.255.255.0 U 0 0 0 ens33 169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 ens33 192.168.10.0 0.0.0.0 255.255.255.0 U 0 0 0 ens38 0.0.0.0 10.10.10.2 0.0.0.0 UG 0 0 0 ens33 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | [root@osyunwei ~] # netstat -a Active Internet connections (servers and established) Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 0 *:54569 *:* LISTEN tcp 0 0 *:sunrpc *:* LISTEN tcp 0 0 *: ssh *:* LISTEN tcp 0 0 localhost:ipp *:* LISTEN tcp 0 0 localhost:smtp *:* LISTEN .....(省略)..... Active UNIX domain sockets (servers and established) Proto RefCnt Flags Type State I-Node Path unix 18 [ ] DGRAM 14606 /dev/log unix 2 [ ACC ] STREAM LISTENING 15536 @ /var/run/hald/dbus-Rat1Ns9j6z unix 2 [ ACC ] STREAM LISTENING 16112 /var/run/pcscd . comm unix 2 [ ACC ] STREAM LISTENING 14153 @ISCSID_UIP_ABSTRACT_NAMESPACE .....(省略)..... |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | [root@osyunwei ~] # netstat -ta Active Internet connections (servers and established) Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 0 *:54569 *:* LISTEN tcp 0 0 *:sunrpc *:* LISTEN tcp 0 0 *: ssh *:* LISTEN tcp 0 0 localhost:ipp *:* LISTEN tcp 0 0 localhost:smtp *:* LISTEN tcp 0 64 10.10.10.139: ssh 10.10.10.1:52401 ESTABLISHED tcp 0 0 10.10.10.139: ssh 10.10.10.1:56538 ESTABLISHED tcp 0 0 *:sunrpc *:* LISTEN tcp 0 0 *:44980 *:* LISTEN tcp 0 0 *: ssh *:* LISTEN tcp 0 0 localhost:ipp *:* LISTEN tcp 0 0 localhost:smtp *:* LISTEN |
1 2 3 4 5 6 7 8 9 10 11 12 | [root@osyunwei ~] # netstat -ua Active Internet connections (servers and established) Proto Recv-Q Send-Q Local Address Foreign Address State udp 0 0 *:sunrpc *:* udp 0 0 *:756 *:* udp 0 0 *:ipp *:* udp 0 0 *:ldaps *:* udp 0 0 *:36110 *:* udp 0 0 localhost:814 *:* udp 0 0 *:sunrpc *:* udp 0 0 *:756 *:* udp 0 0 *:55832 *:* |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | [root@osyunwei ~] # netstat -tan Active Internet connections (servers and established) Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 0 0.0.0.0:54569 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN tcp 0 64 10.10.10.139:22 10.10.10.1:52401 ESTABLISHED tcp 0 0 10.10.10.139:22 10.10.10.1:56538 ESTABLISHED tcp 0 0 :::111 :::* LISTEN tcp 0 0 :::44980 :::* LISTEN tcp 0 0 :::22 :::* LISTEN tcp 0 0 ::1:631 :::* LISTEN tcp 0 0 ::1:25 :::* LISTEN |
1 2 3 4 5 6 7 8 9 10 11 12 | [root@osyunwei ~] # netstat -uan Active Internet connections (servers and established) Proto Recv-Q Send-Q Local Address Foreign Address State udp 0 0 0.0.0.0:111 0.0.0.0:* udp 0 0 0.0.0.0:756 0.0.0.0:* udp 0 0 0.0.0.0:631 0.0.0.0:* udp 0 0 0.0.0.0:636 0.0.0.0:* udp 0 0 0.0.0.0:36110 0.0.0.0:* udp 0 0 127.0.0.1:814 0.0.0.0:* udp 0 0 :::111 :::* udp 0 0 :::756 :::* udp 0 0 :::55832 :::* |
1 2 3 4 5 6 7 8 9 10 11 12 13 | [root@osyunwei ~] # netstat -tnl Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 0 0.0.0.0:54569 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN tcp 0 0 :::111 :::* LISTEN tcp 0 0 :::44980 :::* LISTEN tcp 0 0 :::22 :::* LISTEN tcp 0 0 ::1:631 :::* LISTEN tcp 0 0 ::1:25 :::* LISTEN |
1 2 3 4 5 6 7 8 9 10 11 12 | [root@osyunwei ~] # netstat -unl Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State udp 0 0 0.0.0.0:111 0.0.0.0:* udp 0 0 0.0.0.0:756 0.0.0.0:* udp 0 0 0.0.0.0:631 0.0.0.0:* udp 0 0 0.0.0.0:636 0.0.0.0:* udp 0 0 0.0.0.0:36110 0.0.0.0:* udp 0 0 127.0.0.1:814 0.0.0.0:* udp 0 0 :::111 :::* udp 0 0 :::756 :::* udp 0 0 :::55832 :::* |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | [root@osyunwei ~] # netstat -tunl Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 0 0.0.0.0:54569 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN tcp 0 0 :::111 :::* LISTEN tcp 0 0 :::44980 :::* LISTEN tcp 0 0 :::22 :::* LISTEN tcp 0 0 ::1:631 :::* LISTEN tcp 0 0 ::1:25 :::* LISTEN udp 0 0 0.0.0.0:111 0.0.0.0:* udp 0 0 0.0.0.0:756 0.0.0.0:* udp 0 0 0.0.0.0:631 0.0.0.0:* udp 0 0 0.0.0.0:636 0.0.0.0:* udp 0 0 0.0.0.0:36110 0.0.0.0:* udp 0 0 127.0.0.1:814 0.0.0.0:* udp 0 0 :::111 :::* udp 0 0 :::756 :::* udp 0 0 :::55832 :::* |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | [root@osyunwei ~] # netstat -tunlp Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID /Program name tcp 0 0 0.0.0.0:54569 0.0.0.0:* LISTEN 1910 /rpc .statd tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 1853 /rpcbind tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 2223 /sshd tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 1985 /cupsd tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 2305 /master tcp 0 0 :::111 :::* LISTEN 1853 /rpcbind tcp 0 0 :::44980 :::* LISTEN 1910 /rpc .statd tcp 0 0 :::22 :::* LISTEN 2223 /sshd tcp 0 0 ::1:631 :::* LISTEN 1985 /cupsd tcp 0 0 ::1:25 :::* LISTEN 2305 /master udp 0 0 0.0.0.0:111 0.0.0.0:* 1853 /rpcbind udp 0 0 0.0.0.0:756 0.0.0.0:* 1853 /rpcbind udp 0 0 0.0.0.0:631 0.0.0.0:* 1985 /cupsd udp 0 0 0.0.0.0:636 0.0.0.0:* 1781 /portreserve udp 0 0 0.0.0.0:36110 0.0.0.0:* 1910 /rpc .statd udp 0 0 127.0.0.1:814 0.0.0.0:* 1910 /rpc .statd udp 0 0 :::111 :::* 1853 /rpcbind udp 0 0 :::756 :::* 1853 /rpcbind udp 0 0 :::55832 :::* 1910 /rpc .statd |
1 2 3 4 5 6 7 8 9 | [root@localhost ~] # netstat -i Kernel Interface table Iface MTU RX-OK RX-ERR RX-DRP RX-OVR TX-OK TX-ERR TX-DRP TX-OVR Flg ens33 1500 5128 0 0 0 3702 0 0 0 BMRU ens38 1500 449 0 0 0 8 0 0 0 BMRU lo 65536 3 0 0 0 3 0 0 0 LRU 或者: [root@localhost ~] # netstat -I |
1 2 3 4 | [root@localhost ~] # netstat -Iens33 #注意-I选项和指定接口之间不能有空格; Kernel Interface table Iface MTU RX-OK RX-ERR RX-DRP RX-OVR TX-OK TX-ERR TX-DRP TX-OVR Flg ens33 1500 5155 0 0 0 3720 0 0 0 BMRU |
1 2 3 4 5 6 7 | [root@localhost ~] # ip link #此时list或show可省略; 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT qlen 1 link /loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT qlen 1000 link /ether 00:0c:29:c8:ff:4e brd ff:ff:ff:ff:ff:ff 3: ens38: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT qlen 1000 link /ether 00:0c:29:c8:ff:58 brd ff:ff:ff:ff:ff:ff |
1 2 3 | [root@localhost ~] # ip link show ens38 #查看指定接口属性时,show或list不能省略; 3: ens38: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT qlen 1000 link /ether 00:0c:29:c8:ff:58 brd ff:ff:ff:ff:ff:ff |
1 2 3 4 5 | 先查看ens38接口的状态: [root@localhost ~] # ip link show ens38 3: ens38: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT qlen 1000 #ens38接口处于UP状态; link /ether 00:0c:29:c8:ff:58 brd ff:ff:ff:ff:ff:ff |
1 2 3 4 5 | [root@localhost ~] # ip link set ens38 down [root@localhost ~] # ip link show ens38 3: ens38: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast state DOWN mode DEFAULT qlen 1000 #ens38接口处于DOWN状态; link /ether 00:0c:29:c8:ff:58 brd ff:ff:ff:ff:ff:ff |
1 2 3 4 5 | [root@localhost ~] # ip link set ens38 up [root@localhost ~] # ip link show ens38 3: ens38: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT qlen 1000 #ens38接口已重新启用; link /ether 00:0c:29:c8:ff:58 brd ff:ff:ff:ff:ff:ff |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | [root@localhost ~] # ip link set ens38 name ens30 RTNETLINK answers: Device or resource busy #显示繁忙,接口必须在DOWN状态下才可重命名; [root@localhost ~] # ip link set ens38 down [root@localhost ~] # ip link set ens38 name ens30 #命令键入后没有任何提示,说明修改完成; [root@localhost ~] # ip link show ens30 3: ens30: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast state DOWN mode DEFAULT qlen 1000 link /ether 00:0c:29:c8:ff:58 brd ff:ff:ff:ff:ff:ff #查看ens30接口二层属性; [root@localhost ~] # ip link show ens38 Device "ens38" does not exist. #原来的ens38已不存在; [root@localhost ~] # ip link set ens30 up #启用修改完成的ens30接口; [root@localhost ~] # ip link show ens30 3: ens30: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT qlen 1000 link /ether 00:0c:29:c8:ff:58 brd ff:ff:ff:ff:ff:ff |
1 2 3 4 5 | [root@localhost ~] # ip link set ens30 mtu 1400 multicast off [root@localhost ~] # ip link show ens30 3: ens30: <BROADCAST,UP,LOWER_UP> mtu 1400 qdisc pfifo_fast state UP mode DEFAULT qlen 1000 #ens的flags中已无MULTICAST属性,且MTU已修改为1400; link /ether 00:0c:29:c8:ff:58 brd ff:ff:ff:ff:ff:ff |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | [root@localhost ~] # ip netns add mynet #先创建名称空间mynet; [root@localhost ~] # ip netns list #查看已有的名称空间; mynet [root@localhost ~] # ip link set ens30 netns mynet #将ens30接口移至名称空间mynet中; [root@localhost ~] # ip netns exec mynet ip link show #在名称空间mynet之上运行命令"ip link show",而"ip netns exec mynet"类似于进入虚拟的名称空间中,在此之上运行COMMAND. 1: lo: <LOOPBACK> mtu 65536 qdisc noop state DOWN mode DEFAULT qlen 1 link /loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 3: ens30: <BROADCAST> mtu 1400 qdisc noop state DOWN mode DEFAULT qlen 1000 link /ether 00:0c:29:c8:ff:58 brd ff:ff:ff:ff:ff:ff [root@localhost ~] # ip link show #重新查看接口属性; 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT qlen 1 link /loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT qlen 1000 link /ether 00:0c:29:c8:ff:4e brd ff:ff:ff:ff:ff:ff #可以发现ens30已经消失了!因为它已经跑到名称空间mynet里去了。 #基于netns这种机制可以搭建复杂的内部网络/虚拟网络。 |
1 | [root@localhost ~] # ip netns add Jack |
1 2 3 4 | [root@localhost ~] # ip netns list Jack mynet #这里显示刚刚创建的Jack以及之前创建的mynet; |
1 2 3 | [root@localhost ~] # ip netns del mynet [root@localhost ~] # ip netns list Jack |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | [root@localhost ~] # ip link #首先查看当前主机上的所有接口属性; 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT qlen 1 link /loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT qlen 1000 link /ether 00:0c:29:c8:ff:4e brd ff:ff:ff:ff:ff:ff 3: ens38: <BROADCAST> mtu 1400 qdisc noop state DOWN mode DEFAULT qlen 1000 link /ether 00:0c:29:c8:ff:58 brd ff:ff:ff:ff:ff:ff [root@localhost ~] # ip netns list #列出所有的netns; Jack [root@localhost ~] # ip link set ens38 netns Jack #将ens38接口放进Jack(netns)中; [root@localhost ~] # ip netns exec Jack ip link #在Jack(netns)中运行"ip link"; 1: lo: <LOOPBACK> mtu 65536 qdisc noop state DOWN mode DEFAULT qlen 1 link /loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 3: ens38: <BROADCAST> mtu 1400 qdisc noop state DOWN mode DEFAULT qlen 1000 link /ether 00:0c:29:c8:ff:58 brd ff:ff:ff:ff:ff:ff [root@localhost ~] # ip netns exec Jack ip addr add 172.16.10.1/24 dev ens38 #在Jack(netns)中为挪进去的ens38接口配置IP/NETMASK; [root@localhost ~] # ip netns exec Jack ip addr show ens38 #在Jack(netns)中查看ens38接口IP地址; 3: ens38: <BROADCAST> mtu 1400 qdisc noop state DOWN qlen 1000 link /ether 00:0c:29:c8:ff:58 brd ff:ff:ff:ff:ff:ff inet 172.16.10.1 /24 scope global ens38 valid_lft forever preferred_lft forever |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | [root@localhost ~] # ip addr list 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1 link /loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1 /8 scope host lo valid_lft forever preferred_lft forever inet6 ::1 /128 scope host valid_lft forever preferred_lft forever 2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link /ether 00:0c:29:c8:ff:4e brd ff:ff:ff:ff:ff:ff inet 10.10.10.140 /24 brd 10.10.10.255 scope global ens33 valid_lft forever preferred_lft forever inet 10.10.10.138 /24 brd 10.10.10.255 scope global secondary ens33 valid_lft forever preferred_lft forever inet6 fe80::20c:29ff:fec8:ff4e /64 scope link valid_lft forever preferred_lft forever 3: ens38: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link /ether 00:0c:29:c8:ff:58 brd ff:ff:ff:ff:ff:ff inet 192.168.10.1 /24 brd 192.168.10.255 scope global ens38 valid_lft forever preferred_lft forever inet6 fe80::20c:29ff:fec8:ff58 /64 scope link valid_lft forever preferred_lft forever 或者: [root@localhost ~] # ip addr show |
1 2 3 4 5 6 7 8 9 10 11 12 | [root@localhost ~] # ip addr show ens33 2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link /ether 00:0c:29:c8:ff:4e brd ff:ff:ff:ff:ff:ff inet 10.10.10.140 /24 brd 10.10.10.255 scope global ens33 valid_lft forever preferred_lft forever inet 10.10.10.138 /24 brd 10.10.10.255 scope global secondary ens33 valid_lft forever preferred_lft forever inet6 fe80::20c:29ff:fec8:ff4e /64 scope link valid_lft forever preferred_lft forever 或者: [root@localhost ~] # ip addr list ens33 |
1 2 3 4 5 6 7 8 9 10 11 | [root@localhost ~] # ip addr add 192.168.20.1/24 dev ens38 [root@localhost ~] # ip addr show ens38 3: ens38: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link /ether 00:0c:29:c8:ff:58 brd ff:ff:ff:ff:ff:ff inet 192.168.10.1 /24 brd 192.168.10.255 scope global ens38 valid_lft forever preferred_lft forever inet 192.168.20.1 /24 scope global ens38 #显示已添加该地址,并作为ens38接口的secondary地址,如果没有指定别名,则该地址在ifconfig命令中不会显示; valid_lft forever preferred_lft forever inet6 fe80::20c:29ff:fec8:ff58 /64 scope link valid_lft forever preferred_lft forever |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | [root@localhost ~] # ip addr add 172.168.10.1/24 dev ens38 label ens38:0 [root@localhost ~] # ip addr show ens38 3: ens38: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link /ether 00:0c:29:c8:ff:58 brd ff:ff:ff:ff:ff:ff inet 192.168.10.1 /24 brd 192.168.10.255 scope global ens38 valid_lft forever preferred_lft forever inet 192.168.20.1 /24 scope global ens38 valid_lft forever preferred_lft forever inet 172.168.10.1 /24 scope global ens38:0 #显示已添加,网卡别名为ens38:0,并作为ens38的secondary地址; valid_lft forever preferred_lft forever inet6 fe80::20c:29ff:fec8:ff58 /64 scope link valid_lft forever preferred_lft forever 用 ifconfig 显示: [root@localhost ~] # ifconfig ens38:0 ens38:0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 172.168.10.1 netmask 255.255.255.0 broadcast 0.0.0.0 ether 00:0c:29:c8:ff:58 txqueuelen 1000 (Ethernet) |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | [root@localhost ~] # ip addr show ens38 3: ens38: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link /ether 00:0c:29:c8:ff:58 brd ff:ff:ff:ff:ff:ff inet 192.168.10.1 /24 brd 192.168.10.255 scope global ens38 valid_lft forever preferred_lft forever inet 192.168.20.1 /24 scope global ens38 #要删除的IP地址; valid_lft forever preferred_lft forever inet 172.168.10.1 /24 scope global ens38:0 valid_lft forever preferred_lft forever inet6 fe80::20c:29ff:fec8:ff58 /64 scope link valid_lft forever preferred_lft forever [root@localhost ~] # [root@localhost ~] # ip addr delete 192.168.20.1/24 dev ens38 [root@localhost ~] # ip addr show ens38 3: ens38: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link /ether 00:0c:29:c8:ff:58 brd ff:ff:ff:ff:ff:ff inet 192.168.10.1 /24 brd 192.168.10.255 scope global ens38 valid_lft forever preferred_lft forever inet 172.168.10.1 /24 scope global ens38:0 valid_lft forever preferred_lft forever inet6 fe80::20c:29ff:fec8:ff58 /64 scope link valid_lft forever preferred_lft forever 显示已经删除。 |
1 2 3 4 | [root@localhost ~] # ip addr flush dev ens38 [root@localhost ~] # ip addr show ens38 3: ens38: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link /ether 00:0c:29:c8:ff:58 brd ff:ff:ff:ff:ff:ff |
1 2 3 4 5 6 7 8 9 | [root@localhost ~] # ip route show default via 10.10.10.2 dev ens33 10.10.10.0 /24 dev ens33 proto kernel scope link src 10.10.10.140 169.254.0.0 /16 dev ens33 scope link metric 1002 172.16.0.0 /16 via 192.168.20.1 dev ens38 src 192.168.30.1 172.16.10.0 /24 via 10.10.10.2 dev ens33 192.168.10.0 /24 dev ens38 proto kernel scope link src 192.168.10.1 192.168.20.0 /24 dev ens38 proto kernel scope link src 192.168.20.1 192.168.30.0 /24 dev ens38 proto kernel scope link src 192.168.30.1 |
1 2 | [root@localhost ~] # ip route show 172.16.0.0/16 172.16.0.0 /16 via 192.168.20.1 dev ens38 src 192.168.30.1 |
1 2 3 4 5 6 7 8 | [root@localhost ~] # ip route add 172.16.10.0/24 via 10.10.10.2 [root@localhost ~] # route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 10.10.10.0 0.0.0.0 255.255.255.0 U 0 0 0 ens33 169.254.0.0 0.0.0.0 255.255.0.0 U 1002 0 0 ens33 172.16.10.0 10.10.10.2 255.255.255.0 UG 0 0 0 ens33 0.0.0.0 10.10.10.2 0.0.0.0 UG 0 0 0 ens33 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | [root@localhost ~] # ip addr add 192.168.10.1/24 dev ens38 #为ens38接口添加地址; [root@localhost ~] # ip addr add 192.168.20.1/24 dev ens38 [root@localhost ~] # ip addr add 192.168.30.1/24 dev ens38 [root@localhost ~] # ip addr show ens38 3: ens38: <BROADCAST,UP,LOWER_UP> mtu 1400 qdisc pfifo_fast state UP qlen 1000 link /ether 00:0c:29:c8:ff:58 brd ff:ff:ff:ff:ff:ff inet 192.168.10.1 /24 scope global ens38 valid_lft forever preferred_lft forever inet 192.168.20.1 /24 scope global ens38 valid_lft forever preferred_lft forever inet 192.168.30.1 /24 scope global ens38 valid_lft forever preferred_lft forever inet6 fe80::20c:29ff:fec8:ff58 /64 scope link valid_lft forever preferred_lft forever [root@localhost ~] # ip route add 172.16.0.0/16 via 192.168.20.1 src 192.168.30.1 [root@localhost ~] # ip route list default via 10.10.10.2 dev ens33 10.10.10.0 /24 dev ens33 proto kernel scope link src 10.10.10.140 169.254.0.0 /16 dev ens33 scope link metric 1002 172.16.0.0 /16 via 192.168.20.1 dev ens38 src 192.168.30.1 #src为192.168.30.1 172.16.10.0 /24 via 10.10.10.2 dev ens33 192.168.10.0 /24 dev ens38 proto kernel scope link src 192.168.10.1 192.168.20.0 /24 dev ens38 proto kernel scope link src 192.168.20.1 192.168.30.0 /24 dev ens38 proto kernel scope link src 192.168.30.1 |
1 2 3 4 5 | [root@localhost ~] # ip route show 172.16.0.0/16 #先查看172.16.0.0/16路由信息; 172.16.0.0 /16 via 192.168.20.1 dev ens38 src 192.168.30.1 #源地址为192.168.30.1; [root@localhost ~] # ip route change 172.16.0.0/16 src 192.168.10.1 #将172.160.0.0/16这条路由的源地址改为192.168.10.1; [root@localhost ~] # ip route show 172.16.0.0/16 172.16.0.0 /16 dev ens38 scope link src 192.168.10.1 #源地址已改动; |
1 2 3 4 5 6 | [root@localhost ~] # ip route change 30.0.0.0/8 via 192.168.20.1 src 192.168.10.1 RTNETLINK answers: No such file or directory #如果使用change命令则无法修改,因为路由30.0.0.0/8事先不存在; [root@localhost ~] # ip route replace 30.0.0.0/8 via 192.168.20.1 src 192.168.10.1 #如果使用replace命令则在键入后无任何信息输出; [root@localhost ~] # ip route show 30.0.0.0/8 #查看30.0.0.0/8路由的信息,以检测该路由是否存在; 30.0.0.0 /8 via 192.168.20.1 dev ens38 src 192.168.10.1 #说明如果指定路由不存在则会自动按指定的属性创建该路由; #ip route replace命令类似于rpm -Uvh(若程序包原先存在则升级,不存在则自动安装); |
1 2 3 4 5 6 7 8 9 10 11 | [root@localhost ~] # ip route del 30.0.0.0/8 [root@localhost ~] # ip route show default via 10.10.10.2 dev ens33 10.10.10.0 /24 dev ens33 proto kernel scope link src 10.10.10.140 169.254.0.0 /16 dev ens33 scope link metric 1002 172.16.0.0 /16 dev ens38 scope link src 192.168.10.1 172.16.10.0 /24 via 10.10.10.2 dev ens33 192.168.10.0 /24 dev ens38 proto kernel scope link src 192.168.10.1 192.168.20.0 /24 dev ens38 proto kernel scope link src 192.168.20.1 192.168.30.0 /24 dev ens38 proto kernel scope link src 192.168.30.1 #可看出30.0.0.0/8路由已被删除; |
1 2 3 | [root@localhost ~] # ip route get 192.168.10.0/16 broadcast 192.168.10.0 dev ens38 src 192.168.10.1 cache < local ,brd> |
1 2 3 4 5 6 7 8 9 10 | [root@localhost ~] # ip route flush 192.168.10.0/24 #删除指定路由; [root@localhost ~] # ip route show default via 10.10.10.2 dev ens33 10.10.10.0 /24 dev ens33 proto kernel scope link src 10.10.10.140 169.254.0.0 /16 dev ens33 scope link metric 1002 172.16.0.0 /16 dev ens38 scope link src 192.168.10.1 172.16.10.0 /24 via 10.10.10.2 dev ens33 192.168.20.0 /24 dev ens38 proto kernel scope link src 192.168.20.1 192.168.30.0 /24 dev ens38 proto kernel scope link src 192.168.30.1 #指定路由已被删除,功能类似del; |
1 2 3 4 5 | [root@localhost ~] # ss -tan '( dport = :22 or sport = :22 )' State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 128 *:22 *:* ESTAB 0 52 10.10.10.140:22 10.10.10.1:56108 LISTEN 0 128 :::22 :::* |
1 2 3 | [root@localhost ~] # ss -tan state established Recv-Q Send-Q Local Address:Port Peer Address:Port 0 52 10.10.10.140:22 10.10.10.1:56108 |
1 2 | [root@localhost ~] # vim /etc/resolv.conf nameserver 114.114.114.114 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | [root@localhost ~] # dig -t A public1.114dns.com. ; <<>> DiG 9.9.4-RedHat-9.9.4-37.el7 <<>> -t A public1.114dns.com. ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id : 64858 ;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1 ;; OPT PSEUDOSECTION: ; EDNS: version: 0, flags:; udp: 4096 ;; QUESTION SECTION: ;public1.114dns.com. IN A ;; ANSWER SECTION: public1.114dns.com. 441 IN A 114.114.114.114 #解出地址,说明该DNS服务器地址有效; ;; Query time : 38 msec ;; SERVER: 114.114.114.114 #53(114.114.114.114) ;; WHEN: Sat Feb 11 19:38:48 CST 2017 ;; MSG SIZE rcvd: 63 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | [root@localhost ~] # dig -x 114.114.114.114 #由IP地址解析出FQDN; ; <<>> DiG 9.9.4-RedHat-9.9.4-37.el7 <<>> -x 114.114.114.114 ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id : 48274 ;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1 ;; OPT PSEUDOSECTION: ; EDNS: version: 0, flags:; udp: 4096 ;; QUESTION SECTION: ;114.114.114.114. in -addr.arpa. IN PTR ;; ANSWER SECTION: 114.114.114.114. in -addr.arpa. 330 IN PTR public1.114dns.com. #获取FQDN,反解成功; ;; Query time : 39 msec ;; SERVER: 114.114.114.114 #53(114.114.114.114) ;; WHEN: Sat Feb 11 19:42:21 CST 2017 ;; MSG SIZE rcvd: 89 |
1 2 3 4 5 6 7 8 | [root@localhost ~] # nslookup 114.114.114.114 Server: 114.114.114.114 Address: 114.114.114.114 #53 Non-authoritative answer: 114.114.114.114. in -addr.arpa name = public1.114dns.com. Authoritative answers can be found from: |
1 2 3 4 5 6 7 8 | [root@localhost ~] # nslookup 114.114.114.114 Server: 114.114.114.114 Address: 114.114.114.114 #53 Non-authoritative answer: 114.114.114.114. in -addr.arpa name = public1.114dns.com. Authoritative answers can be found from: |
1 2 | [root@localhost ~] # host public1.114dns.com. public1.114dns.com has address 114.114.114.114 |
1 2 | [root@localhost ~] # host 114.114.114.114 114.114.114.114. in -addr.arpa domain name pointer public1.114dns.com. |
1 2 | [root@localhost ~] # hostname localhost.localdomain |
1 | [root@localhost ~] # hostname www.iTab.com |
1 2 3 4 5 6 7 8 9 10 11 12 | [root@localhost ~] # hostnamectl Static hostname : localhost Transient hostname : localhost.localdomain Icon name: computer-vm Chassis: vm Machine ID: dca382f93a984870b93aab37ceaf66dc Boot ID: 033b1679890b4e6e9c1bafe6528e9c8e Virtualization: vmware Operating System: CentOS Linux 7 (Core) CPE OS Name: cpe: /o :centos:centos:7 Kernel: Linux 3.10.0-514.el7.x86_64 Architecture: x86-64 |
1 2 3 4 5 6 7 8 9 10 11 12 13 | [root@localhost ~] # hostnamectl set-hostname www.iTab.com [root@localhost ~] # hostnamectl #注意:该命令会修改配置文件,不会立即生效,但重启后会永久生效; Static hostname : www.itab.com Pretty hostname : www.iTab.com Icon name: computer-vm Chassis: vm Machine ID: dca382f93a984870b93aab37ceaf66dc Boot ID: 033b1679890b4e6e9c1bafe6528e9c8e Virtualization: vmware Operating System: CentOS Linux 7 (Core) CPE OS Name: cpe: /o :centos:centos:7 Kernel: Linux 3.10.0-514.el7.x86_64 Architecture: x86-64 |
1 2 | [root@localhost ~] # vim /etc/sysconfig/network HOSTNAME=www.iTab.com #注意:此方法不会立即有效,但重启会一直有效; |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | 配置文件参数: DEVICE:此配置文件对应的设备的名称; ONBOOT:在系统引导过程中,是否激活此接口; BOOTPROTO:激活此接口时通过什么协议来配置此接口的属性;常用的有:dhcp, bootp, static, none; PEERDNS:如果BOOTPROTO的值为 "dhcp" ,则是否允许dhcp server分配的DNS服务器指向覆盖本地手动指定的DNS服务器指向;默认为允许( yes ); UUID:此设备的唯一标识; IPV6INIT:是否初始化IPv6; TYPE:接口类型,常见的有:Ethernet, Bridge; DNS1:第一DNS服务器指向; DNS2:备用DNS服务器指向; DOMAIN:指定搜索域; IPADDR:IP地址; NETMASK:子网掩码; GATEWAY:默认网关;在CentOS 7上还支持使用PREFIX以长度方式指明子网掩码; USERCTL:是否允许普通用户控制此设备; HWADDR:此设备的MAC地址; NM_CONTROLLED:是否使用NetworkManager服务来控制此接口; |
1 2 | 方式一: # /etc/init.d/network restart 方式二: # service network restart |
1 2 | 方式一(推荐): # systemctl restart network.service 方式二: # service network restart |
1 2 | network NetworkManager |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | [root@loaclhost ~] # ifconfig ens33:0 192.168.1.1/24 [root@loaclhost ~] # ifconfig ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 10.10.10.140 netmask 255.255.255.0 broadcast 10.10.10.255 inet6 fe80::e927:7013:71ec:ffd2 prefixlen 64 scopeid 0x20<link> ether 00:0c:29:c8:ff:4e txqueuelen 1000 (Ethernet) RX packets 56804 bytes 12970225 (12.3 MiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 18808 bytes 2949415 (2.8 MiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 ens33:0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.1.1 netmask 255.255.255.0 broadcast 192.168.1.255 ether 00:0c:29:c8:ff:4e txqueuelen 1000 (Ethernet) ......(以下省略)...... |
1 2 3 4 5 6 | DEVICE=IFACE_LABEL #指定网卡别名; BOOTPROTO=static #网上别名不支持动态获取地址;支持static, none; IPADDR= #IP地址; NETMASK= #子网掩码; 删除原有其他接口的HWADDR 删除原有其他接口的UUID |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | [root@loaclhost ~] # cp /etc/sysconfig/network-scripts/ifcfg-ens33 /etc/sysconfig/network-scripts/ifcfg-ens33:0 [root@loaclhost ~] # vim /etc/sysconfig/network-scripts/ifcfg-ens33:0 TYPE=Ethernet BOOTPROTO=static DEFROUTE= yes DEVICE=ens33:0 ONBOOT= yes IPADDR=192.168.1.1 NETMASK=255.255.255.0 #保存并退出; [root@loaclhost ~] # systemctl restart network #重启网络服务network; [root@www ~] # ifconfig ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 10.10.10.140 netmask 255.255.255.0 broadcast 10.10.10.255 inet6 fe80::20c:29ff:fec8:ff4e prefixlen 64 scopeid 0x20<link> ether 00:0c:29:c8:ff:4e txqueuelen 1000 (Ethernet) RX packets 56847 bytes 12975355 (12.3 MiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 18844 bytes 2952385 (2.8 MiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 ens33:0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.1.1 netmask 255.255.255.0 broadcast 192.168.1.255 ether 00:0c:29:c8:ff:4e txqueuelen 1000 (Ethernet) #配置成功! ......(以下省略)...... |
1 | TARGET via GW |
1 2 3 4 | ADDRESS #=TARGET NETMASK #=MASK GATEWAY #=NEXTHOP #其中'#'为数字,表示第几组路由条目; |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | [root@localhost ~] # route -n #配置前先查看路由表; Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 10.10.10.0 0.0.0.0 255.255.255.0 U 100 0 0 ens33 0.0.0.0 10.10.10.2 0.0.0.0 UG 100 0 0 ens33 [root@localhost ~] # vim /etc/sysconfig/network-scripts/route-ens33 #手动编辑路由配置文件; 100.0.0.0 /8 via 10.10.10.2 #采用每一行一个路由条目方式; [root@localhost ~] # systemctl restart network #重启网络服务network; [root@localhost ~] # route -n #查看路由表; Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 10.10.10.0 0.0.0.0 255.255.255.0 U 100 0 0 ens33 100.0.0.0 10.10.10.2 255.0.0.0 UG 100 0 0 ens33 #配置成功; 0.0.0.0 10.10.10.2 0.0.0.0 UG 100 0 0 ens33 |
1 | [root@localhost ~] # nmtui |
1 2 | [root@localhost ~] # vim /etc/sysconfig/network-scripts/ifcfg-ens33 BOOTPROTO=dhcp |
转载地址:http://ufpab.baihongyu.com/