由于都是技术文档,就不做过多的介绍和解释,直接进入具体操作步骤
1. 有了弹性网卡,需要绑定主机才能够进行其他相关的配置
进入腾讯云进行弹性网卡与云主机的绑定
2. 弹性网卡的配置
vim /etc/sysconfig/network-scripts/ifcfg-eth0
vim /etc/sysconfig/network-scripts/ifcfg-eth0# 主网卡
# Created by cloud-init on instance boot automatically, do not edit.
#
BOOTPROTO=none# 获取IP方式
DEVICE=eth0# 网卡名称
HWADDR=# MAC地址
NM_CONTROLLED=yes
ONBOOT=yes
TYPE=Ethernet
USERCTL=no
IPADDR=# 主IP
NETMASK=# 子网掩码
GETEWAY=# 网关
#下面的为腾讯云里面的弹性公网IP的内网IP
IPADDR1='IP address'
IPADDR2='IP address'
IPADDR3=‘’IP address'
示例:
# cat /etc/sysconfig/network-scripts/ifcfg-eth0
# Created by cloud-init on instance boot automatically, do not edit.
#
##BOOTPROTO=dhcp
##DEVICE=eth0
##HWADDR=52:54:00:99:08:70
##NM_CONTROLLED=no
##ONBOOT=yes
##TYPE=Ethernet
##USERCTL=no
##PERSISTENT_DHCLIENT=yes
BOOTPROTO=none
DEVICE=eth0
HWADDR=
NM_CONTROLLED=yes
ONBOOT=yes
TYPE=Ethernet
USERCTL=no
IPADDR=
NETMASK=
GETEWAY=
IPADDR1='172.21.0.2'
IPADDR2='172.21.0.13'
#PERSISTENT_DHCLIENT=yes
3. 增加另一个网卡(根据需求进行)
vim /etc/sysconfig/network-scripts/ifcfg-eth1
vim /etc/sysconfig/network-scripts/ifcfg-eth1# 辅助网卡
# Created by cloud-init on instance boot automatically, do not edit.
#
BOOTPROTO=none
DEVICE=eth1
HWADDR=# 网卡的MAC地址,可通过腾讯云上网卡的信息查看
IPADDR=# 根据实际填写,主IP地址(内网IP)
NETMASK=# 根据实际填写,,子网掩码
GATEWAY=# 根据实际填写,网关
ONBOOT=yes
#下面的为腾讯云里面的弹性公网IP的内网IP
IPADDR1='IP address'
IPADDR2='IP address'
IPADDR3=‘’IP address'
示例:
# cat /etc/sysconfig/network-scripts/ifcfg-eth1
# Created by cloud-init on instance boot automatically, do not edit.
#
##BOOTPROTO=dhcp
##DEVICE=eth0
##HWADDR=52:54:00:99:08:70
##NM_CONTROLLED=no
##ONBOOT=yes
##TYPE=Ethernet
##USERCTL=no
##PERSISTENT_DHCLIENT=yes
BOOTPROTO=none
DEVICE=eth1
HWADDR=
NM_CONTROLLED=yes
ONBOOT=yes
TYPE=Ethernet
USERCTL=no
IPADDR=
NETMASK=
GETEWAY=
IPADDR1='172.21.0.9'
IPADDR2='172.21.0.16'
#PERSISTENT_DHCLIENT=yes
4. 配置完成后需要需要关闭反向过滤,如果不关闭,在本机ping弹性公网IP会不成功
注意:反向过滤指系统在接收到一个 IP 包后检查该 IP 是否符合要求,不合要求则被丢弃。
例如,用户在 A 网卡上收到一个 IP 包,发送 IP 为 B。而给 B 的 IP 发送时应该用的网卡不是 A,则会丢弃。
由于默认路由走的是主网卡,所以开启反向过滤后,辅助网卡上的 IP 会 ping 不通。
在下面的配置文件里面关闭反向过滤
vim /etc/sysctl.conf
vim /etc/sysctl.conf
net.ipv4.conf.default.rp_filter = 0
net.ipv4.conf.all.rp_filter = 0
net.ipv4.conf.eth0.rp_filter = 0
net.ipv4.conf.eth1.rp_filter = 0
示例:
# cat /etc/sysctl.conf
kernel.printk = 5
5. 重启服务
systemctl restart network
6. 检查确认
ip addr
示例:
# 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
2: eth0: mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 52:54:00:99:08:70 brd ff:ff:ff:ff:ff:ff
inet 172.21.0.2/16 brd 172.21.255.255 scope global eth0
valid_lft forever preferred_lft forever
inet 172.21.0.2/20 brd 172.21.15.255 scope global eth0
valid_lft forever preferred_lft forever
inet 172.21.0.13/16 brd 172.21.255.255 scope global secondary eth0
valid_lft forever preferred_lft forever
3: eth1: mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 20:90:6f:07:62:fb brd ff:ff:ff:ff:ff:ff
inet 172.21.0.9/16 brd 172.21.255.255 scope global eth1
valid_lft forever preferred_lft forever
inet 172.21.0.16/16 brd 172.21.255.255 scope global secondary eth1
valid_lft forever preferred_lft forever
7. 本机ping检查
ping -n (number) IPADDR(ip address)
示例:
# ping -n 172.21.0.16
PING 172.21.0.16 (172.21.0.16) 56(84) bytes of data.
64 bytes from 172.21.0.16: icmp_seq=1 ttl=64 time=0.014 ms
64 bytes from 172.21.0.16: icmp_seq=2 ttl=64 time=0.021 ms
64 bytes from 172.21.0.16: icmp_seq=3 ttl=64 time=0.028 ms
-n 是指ping 数字地址(39.156.69.79),不是域名地址()
若用指定 ping 的次数,使用 -c 参数:
ping -n 172.21.0.16-c 3
# ping -n 172.21.0.16 -c 3
PING 172.21.0.16 (172.21.0.16) 56(84) bytes of data.
64 bytes from 172.21.0.16: icmp_seq=1 ttl=64 time=0.011 ms
64 bytes from 172.21.0.16: icmp_seq=2 ttl=64 time=0.023 ms
64 bytes from 172.21.0.16: icmp_seq=3 ttl=64 time=0.019 ms
--- 172.21.0.16 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 1999ms
rtt min/avg/max/mdev = 0.011/0.017/0.023/0.007 ms
能够ping通则成功
参考推荐:
如果觉得《腾讯云服务器增加网卡 腾讯云绑定和配置弹性网卡》对你有帮助,请点赞、收藏,并留下你的观点哦!