MIIBlog
一点水只有放进大海里才永远不会干涸

云服务器多网卡配置实践

环境概述:

系统环境:标准型S2、1核2G、1Mbps、Centos7.4 64位、腾讯云、北京一区、VPC(私有网络)

远程连接工具:xshell5

目标:

为服务器配置 2个网卡,每个网卡配置2个内网ip、2个外网ip,共计4个外网ip、4个内网ip

开始配置

在服务器创建完之后,会有一个弹性网卡–主网卡,如下方截图所示:https://console.cloud.tencent.com/vpc/eni

一、为主网卡再绑定一个外网ip、一个内网ip,如下方截图

1)分配内网ip

2)绑定弹性公网ip;如果已有弹性公网ip,选择“使用现有EIP绑定”;如果没有,则选择“新建EIP绑定”即可

3)已将一个弹性网卡绑定2个外网ip、2个内网ip之后的效果图

4)远程连接服务器,修改网卡配置文件

[[email protected]_0_100_centos ~]

# cp /etc/sysconfig/network-scripts/ifcfg-eth0{,.bak} # 修改网卡配置文件

[[email protected]_0_100_centos ~]

# vim /etc/sysconfig/network-scripts/ifcfg-eth0 # Created by cloud-init on instance boot automatically, do not edit. # BOOTPROTO=none # 不要设置dhcp DEVICE=eth0 IPADDR0=10.0.0.100 NETMASK0=255.255.255.0 IPADDR1=10.0.0.101 NETMASK1=255.255.255.0 GATEWAY=10.0.0.1 NM_CONTROLLED=no ONBOOT=yes TYPE=Ethernet USERCTL=no PERSISTENT_DHCLIENT=yes # 重启网卡

[[email protected]_0_100_centos ~]

# systemctl restart network.service # 查看配置成功后的效果

[[email protected]_0_100_centos ~]

# ip addr 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 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 52:54:00:8a:7a:64 brd ff:ff:ff:ff:ff:ff inet 10.0.0.100/24 brd 10.0.0.255 scope global eth0 valid_lft forever preferred_lft forever inet 10.0.0.101/24 brd 10.0.0.255 scope global secondary eth0 valid_lft forever preferred_lft forever

5)验证配置的外网IP是否可用

二、添加辅助网卡及配置

1)添加辅助网卡

2)绑定弹性公网ip

3)绑定云主机

4)远程连接服务器,修改网卡配置文件、关闭rp_filter校验

[[email protected]_0_100_centos ~]

# cp /etc/sysconfig/network-scripts/ifcfg-eth{0,1} # 修改ifcfg-eh1网卡

[[email protected]_0_100_centos ~]

# vim /etc/sysconfig/network-scripts/ifcfg-eth1 # Created by cloud-init on instance boot automatically, do not edit. # BOOTPROTO=none # 不要设置dhcp DEVICE=eth1 # 网卡设置名修改为eth1 IPADDR0=10.0.1.100 NETMASK0=255.255.255.0 IPADDR1=10.0.1.101 NETMASK1=255.255.255.0 GATEWAY=10.0.1.1 # 网关 10.0.1.1 NM_CONTROLLED=no ONBOOT=yes TYPE=Ethernet USERCTL=no PERSISTENT_DHCLIENT=yes # 关闭 rp_filter 校验

[[email protected]_0_100_centos ~]

# vim /etc/sysctl.conf # 找到第16行的rp_filter,注释掉 #net.ipv4.conf.default.rp_filter = 1 # 在文件结尾加上如下4行 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 # 重启网卡

[[email protected]_0_100_centos ~]

# systemctl restart network.service # 查看配置成功后的效果

[[email protected]_0_100_centos ~]

# ip addr 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 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 52:54:00:8a:7a:64 brd ff:ff:ff:ff:ff:ff inet 10.0.0.100/24 brd 10.0.0.255 scope global eth0 valid_lft forever preferred_lft forever inet 10.0.0.101/24 brd 10.0.0.255 scope global secondary eth0 valid_lft forever preferred_lft forever 3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 20:90:6f:7c:98:c9 brd ff:ff:ff:ff:ff:ff inet 10.0.1.100/24 brd 10.0.1.255 scope global eth1 valid_lft forever preferred_lft forever inet 10.0.1.101/24 brd 10.0.1.255 scope global secondary eth1 valid_lft forever preferred_lft forever

5)验证配置的外网IP是否可用

绑定安全组

  到目前为止已经配置成功,需要注意一点,如果服务器绑定了安全组,之前绑定的安全组不会自动绑定到辅助网卡上,需要**手动绑定安全组**:

参考文档

云服务器概述:https://cloud.tencent.com/document/product/213/495

弹性网卡帮助文档:https://cloud.tencent.com/document/product/215/6513

弹性网卡绑定和配置云主机:https://cloud.tencent.com/document/product/576/18535

安全组帮助文档:https://cloud.tencent.com/document/product/213/18197#common

注意:

本博文仅供参考,读者可根据自己的实际情况,进行配置。

赞(0) 打赏
未经允许不得转载:MII Blog » 云服务器多网卡配置实践

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

优质资源 优质分享

捐赠投稿

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏