Centos 添加双网卡 (生产环境配置记录)

1、在虚拟机中添加网卡2

[root@ntpserver network-scripts]# ip addr

1: lo: mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000

    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: ens192: mtu 1500 qdisc mq state UP group default qlen 1000

    link/ether 00:50:56:b3:eb:a8 brd ff:ff:ff:ff:ff:ff

    inet 10.6.100.18/25 brd 10.6.100.127 scope global noprefixroute ens192

       valid_lft forever preferred_lft forever

    inet6 fe80::72b3:9725:d92f:306/64 scope link tentative noprefixroute dadfailed

       valid_lft forever preferred_lft forever

    inet6 fe80::2206:e2ec:6f6c:dd4b/64 scope link tentative noprefixroute dadfailed

       valid_lft forever preferred_lft forever

    inet6 fe80::295c:ddf4:9822:5398/64 scope link tentative noprefixroute dadfailed

       valid_lft forever preferred_lft forever

Centos 添加双网卡 (生产环境配置记录)_第1张图片

添加完后多了en34

[root@ntpserver network-scripts]# ip add

1: lo: mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000

    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: ens192: mtu 1500 qdisc mq state UP group default qlen 1000

    link/ether 00:50:56:b3:eb:a8 brd ff:ff:ff:ff:ff:ff

    inet 10.6.100.18/25 brd 10.6.100.127 scope global noprefixroute ens192

       valid_lft forever preferred_lft forever

    inet6 fe80::72b3:9725:d92f:306/64 scope link tentative noprefixroute dadfailed

       valid_lft forever preferred_lft forever

    inet6 fe80::2206:e2ec:6f6c:dd4b/64 scope link tentative noprefixroute dadfailed

       valid_lft forever preferred_lft forever

    inet6 fe80::295c:ddf4:9822:5398/64 scope link tentative noprefixroute dadfailed

       valid_lft forever preferred_lft forever

3: ens34: mtu 1500 qdisc pfifo_fast state DOWN group default qlen 1000

    link/ether 00:0c:29:16:50:c8 brd ff:ff:ff:ff:ff:ff

[root@ntpserver network-scripts]#

2、vim /etc/sysconfig/network-scripts/ifcfg-ens192 #编辑 ens192 网卡

TYPE=Ethernet

PROXY_METHOD=none

BROWSER_ONLY=no

BOOTPROTO=none

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=ens

UUID=1a5b3386-6836-46e3-8823-a4fc5088e0b8

DEVICE=ens192

ONBOOT=yes

DNS1=10.6.100.10

IPADDR=10.6.100.18

PREFIX=25

GATEWAY=10.6.100.1

DEVICE=ens192
TYPE=Ethernet
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=none
MASTER=bond0
SLAVE=yes
USERCTL=no

DEVICE=eth0                # 网口名eth0
TYPE=Ethernet        #网络类型为:Ethernet
ONBOOT=yes                #在系统启动时是否激活网卡
NM_CONTROLLED=yes        #network mamager的参数,实时生效,不需要重启
BOOTPROTO=none        #使用什么协议激活网卡#none表示不使用任何协议 static表示设置静态IP dhcp表示动态获取IP
MASTER=bond0        #指定master为bond0
SLAVE=yes                #是否为附属
#USERCTL=no                  #是否允许非root用户控制该设备,设置为no,只能用root用户更改

[root@ntpserver network-scripts]# cat ifcfg-ens{192,34}

DIVICE=ens192

TYPE=Ethernet

ONBOOT=yes

NM_CONTROLLED=yes

BOOTPROTO=none

MASTER=bond0

SLAVE=yes

USERCTL=no

DEVICE=ens34

TYPE=Ethernet

ONBOOT=yes

NM_CONTROLLED=yes

BOOTPROTO=none

MASTER=bond0

SLAVE=yes

#USERCTL=no

3、vim /etc/sysconfig/network-scripts/ifcfg-ens34 #编辑 ens34网卡

DEVICE=ens34
TYPE=Ethernet
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=none
MASTER=bond0
SLAVE=yes
USERCTL=no

4、vim /etc/sysconfig/network-scripts/ifcfg-bond0 #创建并配置bond0网卡

#bond,是一种通过把多个物理网卡绑定成一个逻辑网卡实现网卡冗余、负载均衡、提高带宽,从而实现网络性能高可用高可靠的技术。

DEVICE=bond0

TYPE=Ethernet //bond
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=none
IPADDR=10.6.100.18
NETMASK=255.255.255.128
GATEWAY=10.6.100.1

USERCTL=no

DNS1=8.8.8.8

5、vi /etc/modprobe.d/dist.conf #配置添加内容

#最后一行添加
alias bond0 bonding
options bond0 miimon=100 mode=6

6、停止 network manager服务

service NetworkManager stop        #解决service network restart 闲置网卡报错问题
chkconfig NetworkManager off        #移除开机启动

7、重启网卡

 service network restart

1.到了这一步最好reboot下,确保下面能一次性成功

2.UUID是唯一的编号,每个网口唯一

3.两个配置文件中HWADDR不能一样,可以不要,因为会自动读取

4.网口切换后 ifconfig bond0查看到的MAC地址还是切换前的MAC地址–>为了防止IP对应MAC地址混乱

8、测试

ping g.cn        #双网卡测试
ifconfig eth0 down        #关闭eth0
ping g.cn        #测试
ifconfig eth0 up        #打开eth0
ifconfig eth1 down        #关闭eth1
ping g.cn        #测试

屏幕剪辑的捕获时间: 9/26/2023 1:45 PM

你可能感兴趣的:(centos,linux,运维)