CentOS 6 網卡名稱
Centos6網卡接口命名方式:promise
網絡接口識別並命名相關的udev配置文件: /etc/udev/rules.d/70-persistent-net.rules
此文件主要是記錄網卡的信息,這個文件在虛擬機克隆的時候比較有用處,通常說來,虛擬機克隆,相應也會把網卡物理地址克隆過來,因此須要到這個文件裏把相應的網卡記錄刪除,而後重啓,或者從新加載網卡驅動服務器
cat /etc/udev/rules.d/70-persistent-net.rules # This file was automatically generated by the /lib/udev/write_net_rules # program, run by the persistent-net-generator.rules rules file. # # You can modify it, as long as you keep each rule on a single # line, and change only the value of the NAME= key. # PCI device 0x8086:0x100f (e1000) SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:ae:f9:a9", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0" # PCI device 0x8086:0x100f (e1000) SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:ae:f9:b3", ATTR{type}=="1", KERNEL=="eth*", NAME="eth1"
查看網卡信息網絡
[root@Centos6 ~]# dmesg |grep -i eth e1000 0000:02:01.0: eth0: (PCI:66MHz:32-bit) 00:0c:29:ae:f9:a9 e1000 0000:02:01.0: eth0: Intel(R) PRO/1000 Network Connection e1000 0000:02:04.0: eth1: (PCI:66MHz:32-bit) 00:0c:29:ae:f9:b3 e1000 0000:02:04.0: eth1: Intel(R) PRO/1000 Network Connection e1000: eth0 NIC Link is Up 1000 Mbps Full Duplex, Flow Control: None eth0: no IPv6 routers present e1000: eth0 NIC Link is Up 1000 Mbps Full Duplex, Flow Control: None ADDRCONF(NETDEV_UP): eth0: link is not ready ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready eth0: no IPv6 routers present e1000 0000:02:01.0: eth0: (PCI:66MHz:32-bit) 00:0c:29:ae:f9:a9 e1000 0000:02:01.0: eth0: Intel(R) PRO/1000 Network Connection ADDRCONF(NETDEV_UP): eth0: link is not ready e1000: eth0 NIC Link is Up 1000 Mbps Full Duplex, Flow Control: None ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready e1000 0000:02:04.0: eth1: (PCI:66MHz:32-bit) 00:0c:29:ae:f9:b3 e1000 0000:02:04.0: eth1: Intel(R) PRO/1000 Network Connection eth0: no IPv6 routers present [root@Centos6 ~]# ethtool -i eth0 driver: e1000 version: 7.3.21-k8-NAPI firmware-version: bus-info: 0000:02:01.0 supports-statistics: yes supports-test: yes supports-eeprom-access: yes supports-register-dump: yes supports-priv-flags: no
卸載網卡驅動app
[root@Centos6 ~]# modprobe -r e1000 或 [root@Centos6 ~]# rmmod e1000
裝載網卡驅動負載均衡
[root@Centos6 ~]# modprobe e1000
網絡配置方式ssh
配置網絡接口
ifconfig命令
ifconfig [interface]
ifconfig -a
ifconfig IFAC [up|down]
ifconfig interface [aftype] option | address …
ifconfig IFACE IP/netmask [up]
ifconfig IFACE IP net mask NETMASK
注意:當即生效
啓用混雜模式:[-] promisesocket
[root@Centos7 ~]# ifconfig eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 10.0.17.93 netmask 255.255.254.0 broadcast 10.0.17.255 inet6 fe80::2ac2:85fc:c7a1:ba02 prefixlen 64 scopeid 0x20<link> ether 00:0c:29:03:fc:f1 txqueuelen 1000 (Ethernet) RX packets 9819 bytes 830422 (810.9 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 75 bytes 13561 (13.2 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 eth1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.1.132 netmask 255.255.255.0 broadcast 192.168.1.255 inet6 fe80::41d4:5d69:d41a:6ae6 prefixlen 64 scopeid 0x20<link> ether 00:0c:29:03:fc:fb txqueuelen 1000 (Ethernet) RX packets 91 bytes 10295 (10.0 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 33 bytes 5706 (5.5 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 24 bytes 2808 (2.7 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 24 bytes 2808 (2.7 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
配置別名eth1:1 192.168.1.200 netmask 255.255.255.0tcp
[root@Centos7 ~]# ifconfig eth1:1 192.168.1.200 netmask 255.255.255.0 [root@Centos7 ~]# ifconfig eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 10.0.17.93 netmask 255.255.254.0 broadcast 10.0.17.255 inet6 fe80::2ac2:85fc:c7a1:ba02 prefixlen 64 scopeid 0x20<link> ether 00:0c:29:03:fc:f1 txqueuelen 1000 (Ethernet) RX packets 11574 bytes 961152 (938.6 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 184 bytes 28669 (27.9 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 eth1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.1.132 netmask 255.255.255.0 broadcast 192.168.1.255 inet6 fe80::41d4:5d69:d41a:6ae6 prefixlen 64 scopeid 0x20<link> ether 00:0c:29:03:fc:fb txqueuelen 1000 (Ethernet) RX packets 94 bytes 10752 (10.5 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 41 bytes 6784 (6.6 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 eth1:1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.1.200 netmask 255.255.255.0 broadcast 192.168.1.255 ether 00:0c:29:03:fc:fb txqueuelen 1000 (Ethernet) 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 28 bytes 3144 (3.0 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 28 bytes 3144 (3.0 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
重啓服務或執行ifconfig eth1:1 down就能夠消除剛配置的別名eth1:1ide
[root@Centos7 ~]# ifconfig eth1:1 down [root@Centos7 ~]# ifconfig eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 10.0.17.93 netmask 255.255.254.0 broadcast 10.0.17.255 inet6 fe80::2ac2:85fc:c7a1:ba02 prefixlen 64 scopeid 0x20<link> ether 00:0c:29:03:fc:f1 txqueuelen 1000 (Ethernet) RX packets 12327 bytes 1022949 (998.9 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 276 bytes 42737 (41.7 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 eth1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.1.132 netmask 255.255.255.0 broadcast 192.168.1.255 inet6 fe80::41d4:5d69:d41a:6ae6 prefixlen 64 scopeid 0x20<link> ether 00:0c:29:03:fc:fb txqueuelen 1000 (Ethernet) RX packets 95 bytes 10854 (10.5 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 42 bytes 6907 (6.7 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 28 bytes 3144 (3.0 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 28 bytes 3144 (3.0 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
route命令
route:路由管理命令
查看:route -n
添加:route add
route add [-net | -host] target [netmask Nm] [gw GW] [[dev] IF]
例如:
目標:192.168.100.1 網關是192.168.1.1工具
[root@Centos7 ~]# route add -host 192.168.100.1 gw 192.168.1.1 dev eth1
刪除
[root@Centos7 ~]# route del -host 192.168.100.1
目標:192.168.0.0 網關:192.168.1.1
[root@Centos7 ~]# route add -net 192.168.0.0 netmask 255.255.255.0 gw 192.168.1.1 dev eth1
刪除
[root@Centos7 ~]# route del -net 192.168.0.0 netmask 255.255.255.0
默認路由,網關:192.168.1.1
[root@Centos7 ~]# route add -net 0.0.0.0 netmask 0.0.0.0 gw 192.168.1.1 dev eth1 或 [root@Centos7 ~]# route add default gw 192.168.1.1 eth1
刪除
[root@Centos7 ~]# route del default gw 192.168.1.1
netstat命令
netstat 顯示網絡鏈接
netstat [--tcp|-t] [--udp|-u] [--raw|-w] [--listening|-l] [--all|-a] [--numeric|-n] [--extend|-e [--extend|-e]] [--program|-p]
[root@Centos7 ~]# netstat -i Kernel Interface table Iface MTU RX-OK RX-ERR RX-DRP RX-OVR TX-OK TX-ERR TX-DRP TX-OVR Flg eth0 1500 21895 0 0 0 1043 0 0 0 BMRU eth1 1500 142 0 0 0 48 0 0 0 BMRU lo 65536 28 0 0 0 28 0 0 0 LRU
root@Centos7 ~]# netstat -I=eth1
Kernel Interface table
Iface MTU RX-OK RX-ERR RX-DRP RX-OVR TX-OK TX-ERR TX-DRP TX-OVR Flg
eth1 1500 142 0 0 0 48 0 0 0 BMRU
[root@Centos7 ~]# ifconfig -s eth1
Iface MTU RX-OK RX-ERR RX-DRP RX-OVR TX-OK TX-ERR TX-DRP TX-OVR Flg
eth1 1500 142 0 0 0 48 0 0 0 BMRU
[root@Centos7 ~]# ifconfig -s
Iface MTU RX-OK RX-ERR RX-DRP RX-OVR TX-OK TX-ERR TX-DRP TX-OVR Flg
eth0 1500 22346 0 0 0 1163 0 0 0 BMRU
eth1 1500 143 0 0 0 48 0 0 0 BMRU
lo 65536 28 0 0 0 28 0 0 0 LRU
ip命令 ip命令:配置Linux網絡屬性 * ip - show / manipulate routing, devices, policy routing and tunnels * ip [OPTIONS] OBJECT {COMMAND | help} * OBJECT := {link|addr|route} * ip link - network device configuration * set dev IFACE * 可設置屬性: * up and down:激活禁用指定接口 * ifup/ifdown * show [dev IFACE]:指定接口 * [up]:僅顯示處於激活狀態的接口 * ip adds {add|del} IFADDR dev STRING * [label|LABEL]:添加地址時指明網卡別名 * [scope {global|link|host}]:指明做用域 * global:全局可用 * link:僅鏈路連接可用 * 本機可用 * [broadcast ADDRESS]:指明廣播地址 * ip address show - look at protocol address * [dev DEVICE] * [lable PATTERN] * [primary and secondary] * ip adds flush:清除協議地址;使用格式同show 例如:
[root@Centos7 ~]# ip addr add 192.168.1.100 dev eth1 label eth1:1
[root@Centos7 ~]# ip a
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: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:03:fc:f1 brd ff:ff:ff:ff:ff:ff
inet 10.0.17.93/23 brd 10.0.17.255 scope global dynamic eth0
valid_lft 534264sec preferred_lft 534264sec
inet6 fe80::2ac2:85fc:c7a1:ba02/64 scope link
valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:03:fc:fb brd ff:ff:ff:ff:ff:ff
inet 192.168.1.132/24 brd 192.168.1.255 scope global dynamic eth1
valid_lft 1575sec preferred_lft 1575sec
inet 192.168.1.100/32 scope global eth1:1
valid_lft forever preferred_lft forever
inet6 fe80::41d4:5d69:d41a:6ae6/64 scope link
valid_lft forever preferred_lft forever
[root@Centos7 ~]# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.0.17.93 netmask 255.255.254.0 broadcast 10.0.17.255
inet6 fe80::2ac2:85fc:c7a1:ba02 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:03:fc:f1 txqueuelen 1000 (Ethernet)
RX packets 26277 bytes 2124374 (2.0 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 1261 bytes 192229 (187.7 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
eth1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.1.132 netmask 255.255.255.0 broadcast 192.168.1.255
inet6 fe80::41d4:5d69:d41a:6ae6 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:03:fc:fb txqueuelen 1000 (Ethernet)
RX packets 156 bytes 18707 (18.2 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 58 bytes 9593 (9.3 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
eth1:1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.1.100 netmask 255.255.255.255 broadcast 0.0.0.0
ether 00:0c:29:03:fc:fb txqueuelen 1000 (Ethernet)
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 28 bytes 3144 (3.0 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 28 bytes 3144 (3.0 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@Centos7 ~]# ip del add 192.168.1.100 dev eth1 label eth1:1
Object "del" is unknown, try "ip help".
[root@Centos7 ~]# ip addr del 192.168.1.100 dev eth1 label eth1:1
Warning: Executing wildcard deletion to stay compatible with old scripts.
Explicitly specify the prefix length (192.168.1.100/32) to avoid this warning.
This special behaviour is likely to disappear in further releases,
fix your scripts!
[root@Centos7 ~]# ip a
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: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:03:fc:f1 brd ff:ff:ff:ff:ff:ff
inet 10.0.17.93/23 brd 10.0.17.255 scope global dynamic eth0
valid_lft 534151sec preferred_lft 534151sec
inet6 fe80::2ac2:85fc:c7a1:ba02/64 scope link
valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:03:fc:fb brd ff:ff:ff:ff:ff:ff
inet 192.168.1.132/24 brd 192.168.1.255 scope global dynamic eth1
valid_lft 1462sec preferred_lft 1462sec
inet6 fe80::41d4:5d69:d41a:6ae6/64 scope link
valid_lft forever preferred_lft forever
[root@Centos7 ~]# ip addr flush dev eth1 label eth1:1
[root@Centos7 ~]# ip a
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: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:03:fc:f1 brd ff:ff:ff:ff:ff:ff
inet 10.0.17.93/23 brd 10.0.17.255 scope global dynamic eth0
valid_lft 534135sec preferred_lft 534135sec
inet6 fe80::2ac2:85fc:c7a1:ba02/64 scope link
valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:03:fc:fb brd ff:ff:ff:ff:ff:ff
inet 192.168.1.132/24 brd 192.168.1.255 scope global dynamic eth1
valid_lft 1446sec preferred_lft 1446sec
inet6 fe80::41d4:5d69:d41a:6ae6/64 scope link
valid_lft forever preferred_lft forever
* ip route - routing table management * 添加路由:ip route add * ip route add TARGET via GW dev IFACE src SOURCE_IP * TARGET: * 主機路由:IP * ip route add 192.168.0.11 via 192.168.1.1 dev eth1 * 網絡路由:NETWORK/MASK * ip route add 192.168.2.0/24 via 192.168.1.1 dev eth1 * 默認網關: * ip route add default via 192.168.1.1 * 刪除路由:ip route del TARGET * 刪除主機路由:ip route del 192.168.0.11 * 刪除網絡路由:ip route del 192.168.2.0/24 * 刪除默認路由:ip route del default via 192.168.1.1 * 顯示路由:ip route show | list * 清空路由表:ip route flush dev IFACE [via PREFIX] * ip route flush dev eth1 (清空全部eth1上的路由表)若是不加 ss命令 * 格式:ss [OPTION]… [FILTER] * netstat經過比那裏proc來獲取socket信息,ss使用netlink與內核tcp_diag模塊通訊獲取socket信息 * 選項 * -t:tcp協議相關 * -u:udp協議相關 * -w:裸套接字相關 * -x:unix sock相關 * -l:listen狀態的連接 * -a:全部 * -n:數字格式 * -p:相關的程序及PID * -e:擴展的信息 * -m:內存用量 * -o:計時器信息 * FILTER:[state TCP-STATE] [EXPRESSION] * TCP的常見狀態: * tcp finite state machine: * LISTEN:監聽 * ESTABLISHED:已創建的連接 * FIN_WAIT_1 * FIN_WAIT_2 * SYN_SENT * SYN_RECV * CLOSED * EXPRESSION: * dport= * sport= * 經常使用組合: * -tan , -tanl, -tanlp , -uan 常見用法 * ss -l 顯示本地打開的全部端口 * ss -pl 顯示每一個進程具體打開的socket * ss -t -a 顯示全部TCP socket * ss -u -a顯示全部的UDP socket * ss -o state established ‘( dport = :ssh or sport = :ssh )’ 顯示全部已創建的ssh鏈接 * ss -o state established ‘( sport = :http or sport = :http )’ 顯示全部已創建的HTTP鏈接 * ss -s 列出當前socket詳細信息 **網絡配置文件** * IP、MASK、GW、DNS相關配置文件:/etc/sysconfig/network-scripts/ifcfg-IFACE * 路由相關的配置文件:/etc/sysconfig/network-scriptes/route-IFACE * /etc/sysconfig/network-scripts/ifcfg-IFACE: * DEVICE:此配置文件應用到的設備 * HWADDR:對應的設備的MAC地址 * BOOTRPROTO:激活此設備時使用的地址配置協議,經常使用的dhcp,static,none,bootp * NM_CONTROLLED:NM時NetworkManager的縮寫,此網卡是否接受NM控制;建議Centos6爲「no」 * ONBOOT:在系統引導時是否激活此設備 * TYEP:接口類型;常見的有Ethernet,Bridge * UUID:設備的唯一標識 * IPADDR:指明IP地址 * NETMASK:子網掩碼 * GATEWAY:默認網關 * DNS1:第一個DNS服務器指向 * DNS2:第二個DNS服務器指向 * USERCTL:普通用戶是否可控制此設備 * REEPDNS:若是BOOTPROTO的值爲「dhcp」,YES將容許dhcp server分配的DNS服務器信息直接覆蓋至/etc/resolv.conf文件,NO不容許修改/etc/resolv.conf * 設備配置被保存在文本文件中 * /etc/sysconfig/network-scripts/ifcfg-<name> * 幫助文檔列出完整選項列表:/usr/share/doc/initcripts-*/sysconfig.txt **nmcli命令** * 地址配置工具:nmcli * nmcli [OPTIONS] OBJECT {COMMAND | help } * device - show and manage network interfaces * nmcli device help * connection - start, stop, and manage network connections * nmcli connection help * 修改IP地址等屬性: * nmcli connection modify IFACE [+|-] setting.property value * setting property: * ipv4.address * ipv4.geteway * ipv4.dns1 * ipv4.method manual | auto * 修改配置文件執行生效:systemctl restart network | nmcli con reload * nmcli 命令生效:nmcli con down eth0;nmcli con up eth0 * NetworkManager 是管理和監控網絡設置的守護進程 * 設備即網絡接口,鏈接是對網絡接口的配置,一個網絡接口可有多個鏈接配置,但同時只有一個鏈接配置生效 * 顯示全部包括不活動的鏈接 * nmcli con show * 顯示全部活動鏈接 * nmcli con show —active * 顯示網絡鏈接配置 * nmcli con show 「System eth0" * 顯示設備狀態 * nmcli dev status * 顯示網絡接口屬性 * nmcli dev show eth0 * 建立新鏈接default,IP自動經過dhcp獲取 * nmcli con add con-name default type Ethernet ifname eth0 * 刪除鏈接 * nmcli con del default * 建立新鏈接static,指定靜態IP,不自動鏈接 * nmcli con add con-name static ifname eth0 autoconnect no type ethernet ipv4.address 192.168.x.10/24 ipv4.gateway 192.168.x.254 使用nmcli配置網絡 * 啓動static鏈接配置 * nmcli con up static * 啓動default鏈接配置 * nmcli con up default * 查看幫助 * nmcli con add help * 修改鏈接設置 * nmcli con mod 「static」 connection.autoconnect no * nmcli con mod 「static」 ipv4.dns 192.168.x.254 * nmcli con mod 「static」 +ipv4.dns 8.8.8.8 * nmcli con mod 「static」 -ipv4.dns 8.8.8.8 * nmcli con mod 「static」 ipv4.address 「192.168.x.10/24 192.168.x.254" * nmcli con mod 「static」 +ipv4.address 10.10.10.10/14 * DNS設置,存放在/etc/resolv.conf文件中 * PEERDNS=no表示當IP經過dhcp自動獲取時,dns還是手動設置,不自動獲取 * 等價下面的命令: * nmcli con mod 「System eth0」 ipv4.ignore-auto-dns yes * 修改配置鏈接後,須要從新加載配置 * nmcli con reload * nmcli con down 「System eth0」 可被自動激活 * nmcli con up 「System eth0」 * nmcli dev dis eth0 禁用網卡,防止被自動激活 * 圖形工具 * nm-connection-editor * 字符工具 * nmtui * nmtui-connect * nmtui-edit * nmtui-hostname **nmcli實現bonding ** bonding的做用: 可將多塊網卡綁定同一個IP地址對外提供服務;可實現高可用或者負載均衡 * 添加bonding接口 * nmcli con add con-name mybond0 type bond ifname bond0 mode active-backup * 添加從屬接口 * nmcli con add type bond-slave ifname ens33 master bond0 * nmcli con add type bond-slave ifname ens34 master bond0 * 注意:無需爲從屬接口提供鏈接名,則該名稱是接口名稱加類型構成 * 要啓動綁定,則必須首先啓動從屬接口 * nmcli con up bond-slave-ens33 * nmcli con up bond-slave-ens34 * 啓動綁定 * nmcli con up mybond0 * 配置IP地址 * nmcli con mod mybond0 ipv4.address 192.168.1.x/24 ipv4.gateway 192.168.1.254 ipv4.method manual * 查看bonding狀態 * cat /proc/net/bonding/bond0 * 刪除bonding綁定 * 關閉bonding * nmcli con down mybond0 * 刪除bonding * nmcli con delete mybond0 * 刪除從屬接口 * nmcli con delete bond-slave-ens33 * nmcli con delete bond-slave-ens34 **網絡組Network Teaming** 網絡組:是將多個網卡聚合在一塊兒,從而實現容錯和提升吞吐量 網絡組不一樣於舊版中bonding技術,提供更好的性能和擴展性 網絡組由內核驅動和teamd守護進程實現 runner多種方式:broadcast, roundrobin, activebackup, loadbalance, lacp 網絡組 * 啓動網絡組接口不會自動啓動網絡組中的port接口 * 啓動網絡組接口中的port接口總會自動啓動網絡組接口 * 禁用網絡組接口會自動禁用網絡組中的port接口 * 沒有port接口的網絡組接口能夠啓動靜態IP鏈接 * 啓用DHCP鏈接時,沒有port接口的網絡組會等待port接口的加入 建立網絡組接口 * nmcli con add con-name CNAME type team ifname IFNAME [config JSON] * CNAME:鏈接名 * IFNAME:接口名 * JSON指定runner方式 * 格式:’{「runner」:{「name」:」METHOD}}' * METHOD * broadcast * roundrobin * activebackup * loadbalance * lacp 建立port接口 * nmcli con add con-name CNAME type team-slave ifname IFNAME master TEAM * CNAME:鏈接名 * IFNAME:網絡接口名 * TEAM:網絡組接口名 * 鏈接名若不指定,默認爲team-slave-IFACE * nmcli dev dis IFNAME * nmcli con up CNAME * IFNAME:設備名 * CNAME:網絡組接口名或port接口 網絡組示例: * nmcli con add con-name myteam0 type team ifname team0 config ‘{「runner」:{「name」:」loadbalance"}}’ ipv4.address 192.168.1.100/24 ipv4.method manual * nmcli con add con-name team0-eth1 type team-slave ifname eth1 master team0 * nmcli con add con-name team0-eth2 type team-slave ifname eth1 master team0 * nmcli con up myteam0 * nmcli con up team0-eth1 * nmcli con up team0-eth2 * teamdctl team0 state * nmcli dev dis eth1 刪除網絡組 * nmcli con down team0 * teamdctl team0 state * nmcli con show * nmcli con del team0-eth0 * nmcli con del team0-eth1 * nmcli con show