操作系统版本:
[root@cjcos01 network-scripts]# cat /etc/redhat-release
Red Hat Enterprise Linux Server release 7.5 (Maipo)
查看网卡、IP等信息:
[root@cjcos01 ~]# ifconfig
enp0s3: flags=4163 mtu 1500
inet 192.168.1.90 netmask 255.255.255.0 broadcast 192.168.1.255
inet6 fe80::e07:b869:9f7b:792a prefixlen 64 scopeid 0x20
ether 08:00:27:bc:de:5e txqueuelen 1000 (Ethernet)
RX packets 929 bytes 1120691 (1.0 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 759 bytes 68662 (67.0 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
enp0s8: flags=4163 mtu 1500
ether 08:00:27:93:03:0a 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
enp0s9: flags=4163 mtu 1500
ether 08:00:27:de:7f:38 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
enp0s10: flags=4163 mtu 1500
ether 08:00:27:56:39:b6 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 mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10
loop txqueuelen 0 (Local Loopback)
RX packets 166 bytes 17894 (17.4 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 166 bytes 17894 (17.4 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
virbr0: flags=4099 mtu 1500
inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255
ether 52:54:00:45:70:b3 txqueuelen 0 (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
查看配置信息
[root@cjcos01 network-scripts]# ls -l ifcfg-*
-rw-r--r-- 1 root root 472 Sep 16 10:23 ifcfg-enp0s3
-rw-r--r--. 1 root root 254 Jan 3 2018 ifcfg-lo
查看nmcli命令
[root@cjcos01 network-scripts]# man -k nmcli
nmcli (1) - command-line tool for controlling NetworkManager
nmcli-examples (7) - usage examples of nmcli
[root@cjcos01 network-scripts]# man nmcli 7
CONNECTION MANAGEMENT COMMANDS
nmcli connection {show | up | down | modify | add | edit | clone | delete | monitor | reload | load | import |
export} [ARGUMENTS...]
添加网卡
[root@cjcos01 network-scripts]# nmcli connection add con-name enp0s8 type ethernet ifname enp0s8 ipv4.method manual ipv4.addresses 192.100.100.10/24 connection.autoconnect yes
Connection 'enp0s8' (f81306db-bac5-4b2c-ac52-b42c0ca52621) successfully added.
[root@cjcos01 network-scripts]# nmcli connection add con-name enp0s9 type ethernet ifname enp0s9 ipv4.method manual ipv4.addresses 192.100.100.20/24 connection.autoconnect yes
Connection 'enp0s9' (587e0d6b-c4af-4273-9c48-bd2f66fbbc84) successfully added.
查看网卡配置
[root@cjcos01 network-scripts]# cat ifcfg-enp0s8
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=none
IPADDR=192.100.100.10
PREFIX=24
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=enp0s8
UUID=f81306db-bac5-4b2c-ac52-b42c0ca52621
DEVICE=enp0s8
ONBOOT=yes
[root@cjcos01 network-scripts]# cat ifcfg-enp0s9
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=none
IPADDR=192.100.100.20
PREFIX=24
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=enp0s9
UUID=587e0d6b-c4af-4273-9c48-bd2f66fbbc84
DEVICE=enp0s9
ONBOOT=yes
查看网卡信息
[root@cjcos01 network-scripts]# nmcli connection show
NAME UUID TYPE DEVICE
enp0s3 b0b58151-2738-4a9b-8e49-30341e577a60 ethernet enp0s3
enp0s8 f81306db-bac5-4b2c-ac52-b42c0ca52621 ethernet enp0s8
enp0s9 587e0d6b-c4af-4273-9c48-bd2f66fbbc84 ethernet enp0s9
virbr0 c6b6e6fd-1b38-4493-865c-317c16360e46 bridge virbr0
删除网卡
[root@cjcos01 network-scripts]# nmcli connection delete enp0s8
Connection 'enp0s8' (2eec6955-a3dd-4909-9cfc-89f06c2a9aca) successfully deleted.
Connection 'enp0s8' (972fecaa-7123-45de-8248-dd77912606a2) successfully deleted.
Connection 'enp0s8' (7916c63a-2c4e-46a5-8dd6-1d752f694825) successfully deleted.
网卡绑定
[root@cjcos01 network-scripts]# nmcli connection add type bond ifname bond0 mode 1 ip4 192.100.100.30/24 ipv4.gateway 192.100.100.254
Connection 'bond-bond0' (80418cf9-d103-4bc3-a5b8-17783a5dd4c5) successfully added.
[root@cjcos01 network-scripts]# nmcli connection add type bond-slave ifname enp0s8 master bond0
Connection 'bond-slave-enp0s8' (9a848655-4f43-423e-b63e-0c382406a208) successfully added.
[root@cjcos01 network-scripts]# nmcli connection add type bond-slave ifname enp0s9 master bond0
Connection 'bond-slave-enp0s9' (df987cba-99bf-444f-a060-e096291a9d3c) successfully added.
查看信息
[root@cjcos01 network-scripts]# nmcli connection show
NAME UUID TYPE DEVICE
bond-bond0 80418cf9-d103-4bc3-a5b8-17783a5dd4c5 bond bond0
enp0s3 b0b58151-2738-4a9b-8e49-30341e577a60 ethernet enp0s3
enp0s8 f81306db-bac5-4b2c-ac52-b42c0ca52621 ethernet enp0s8
enp0s9 587e0d6b-c4af-4273-9c48-bd2f66fbbc84 ethernet enp0s9
virbr0 c6b6e6fd-1b38-4493-865c-317c16360e46 bridge virbr0
bond-slave-enp0s8 9a848655-4f43-423e-b63e-0c382406a208 ethernet --
bond-slave-enp0s9 df987cba-99bf-444f-a060-e096291a9d3c ethernet --
[root@cjcos01 network-scripts]# cat ifcfg-bond-bond0
BONDING_OPTS=mode=active-backup
TYPE=Bond
BONDING_MASTER=yes
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=none
IPADDR=192.100.100.30
PREFIX=24
GATEWAY=192.100.100.254
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=bond-bond0
UUID=80418cf9-d103-4bc3-a5b8-17783a5dd4c5
DEVICE=bond0
ONBOOT=yes
[root@cjcos01 network-scripts]# cat ifcfg-bond-slave-enp0s8
TYPE=Ethernet
NAME=bond-slave-enp0s8
UUID=9a848655-4f43-423e-b63e-0c382406a208
DEVICE=enp0s8
ONBOOT=yes
MASTER=bond0
SLAVE=yes
[root@cjcos01 network-scripts]# cat ifcfg-bond-slave-enp0s9
TYPE=Ethernet
NAME=bond-slave-enp0s9
UUID=df987cba-99bf-444f-a060-e096291a9d3c
DEVICE=enp0s9
ONBOOT=yes
MASTER=bond0
SLAVE=yes
查看网卡绑定信息
[root@cjcos01 network-scripts]# cat /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)
Bonding Mode: fault-tolerance (active-backup)
Primary Slave: None
Currently Active Slave: None
MII Status: down
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0
启动网卡
[root@cjcos01 network-scripts]# nmcli connection up bond-bond0
[root@cjcos01 network-scripts]# nmcli connection up bond-slave-enp0s8
[root@cjcos01 network-scripts]# nmcli connection up bond-slave-enp0s9
查看网卡绑定状态
[root@cjcos01 network-scripts]# cat /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)
Bonding Mode: fault-tolerance (active-backup)
Primary Slave: None
Currently Active Slave: enp0s8
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0
Slave Interface: enp0s8
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 08:00:27:93:03:0a
Slave queue ID: 0
Slave Interface: enp0s9
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 08:00:27:de:7f:38
Slave queue ID: 0
删除网卡绑定
[root@cjcos01 network-scripts]# nmcli connection show
NAME UUID TYPE DEVICE
bond-bond0 80418cf9-d103-4bc3-a5b8-17783a5dd4c5 bond bond0
enp0s3 b0b58151-2738-4a9b-8e49-30341e577a60 ethernet enp0s3
enp0s8 f81306db-bac5-4b2c-ac52-b42c0ca52621 ethernet enp0s8
enp0s9 587e0d6b-c4af-4273-9c48-bd2f66fbbc84 ethernet enp0s9
virbr0 c6b6e6fd-1b38-4493-865c-317c16360e46 bridge virbr0
bond-slave-enp0s8 9a848655-4f43-423e-b63e-0c382406a208 ethernet --
bond-slave-enp0s9 df987cba-99bf-444f-a060-e096291a9d3c ethernet --
[root@cjcos01 network-scripts]# nmcli connection delete bond-bond0
Connection 'bond-bond0' (80418cf9-d103-4bc3-a5b8-17783a5dd4c5) successfully deleted.
[root@cjcos01 network-scripts]# nmcli connection delete bond-slave-enp0s8
Connection 'bond-slave-enp0s8' (9a848655-4f43-423e-b63e-0c382406a208) successfully deleted.
[root@cjcos01 network-scripts]# nmcli connection delete bond-slave-enp0s9
Connection 'bond-slave-enp0s9' (df987cba-99bf-444f-a060-e096291a9d3c) successfully deleted.
欢迎关注我的微信公众号"IT小Chen",共同学习,共同成长!!
!