Linux多网卡多IP配置记录
程序员文章站
2024-02-14 16:48:16
...
腾讯云的机器,加了一块弹性网卡,记录下配置:
配置文件目录
cd /etc/sysconfig/network-scripts/
主网卡配置
cat ifcfg-eth0
# Created by cloud-init on instance boot automatically, do not edit.
#
BOOTPROTO=none
DEFROUTE=yes
DEVICE=eth0
GATEWAY=172.16.0.1
HWADDR=52:54:00:48:4b:1c
IPADDR=172.16.0.8
NETMASK=255.255.240.0
NM_CONTROLLED=no
ONBOOT=yes
TYPE=Ethernet
USERCTL=no
副网卡配置
cat ifcfg-eth1
# edited by Luke.
#
BOOTPROTO=static
# DEFROUTE=yes
DEVICE=eth1
GATEWAY=172.16.0.1
# HWADDR=52:54:00:48:4b:1c
IPADDR=172.16.0.16
NETMASK=255.255.240.0
NM_CONTROLLED=no
ONBOOT=yes
TYPE=Ethernet
#USERCTL=no
关闭 rp_filter 校验
vim /etc/sysctl.conf
net.ipv4.conf.default.rp_filter = 1
修改成:
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
其他IP配置
cat ifcfg-eth0:0
BOOTPROTO=static
DEVICE=eth0:0
IPADDR=172.16.0.10
NETMASK=255.255.240.0
ONBOOT=yes
重启网络&测试
systemctl restart network
ip addr
curl --interface eth0 ip.sb
curl --interface eth1 ip.sb
curl --interface eth0:0 ip.sb
curl --interface eth0:1 ip.sb
转载于:https://my.oschina.net/hawt/blog/1796009