背景说明:
一台物理服务器,有4个网口,其中有2个网口分别接入网线,配置同网段的不同IP
要求,这俩ip使用同网段的其他主机都能ping通,请求哪个ip则有该IP进行相应
Arvin:
配IP
ip addr add 192.168.1.100/24 dev eth0
ip addr add 192.168.1.101/24 dev eth1
Arvin:
编辑 /etc/iproute2/rt_tables,添加两个自定义路由表:
echo "100 eth0_table" >> /etc/iproute2/rt_tables
echo "101 eth1_table" >> /etc/iproute2/rt_tables
Arvin:
为每个路由表添加规则
# eth0的路由表
ip route add default via 192.168.1.1 dev eth0 table eth0_table
ip route add 192.168.1.0/24 dev eth0 table eth0_table
# eth1的路由表
ip route add default via 192.168.1.1 dev eth1 table eth1_table
ip route add 192.168.1.0/24 dev eth1 table eth1_table
Arvin:
设置策略路由
# 源IP 192.168.1.100 使用 eth0_table
ip rule add from 192.168.1.100 lookup eth0_table
# 源IP 192.168.1.101 使用 eth1_table
ip rule add from 192.168.1.101 lookup eth1_table
Arvin:
配置ARP参数
# 启用ARP过滤:确保每个网卡只响应自身IP的ARP请求
sysctl -w net.ipv4.conf.all.arp_filter=1
sysctl -w net.ipv4.conf.eth0.arp_filter=1
sysctl -w net.ipv4.conf.eth1.arp_filter=1
# 设置ARP通告级别(避免错误通告)
sysctl -w net.ipv4.conf.all.arp_announce=2
sysctl -w net.ipv4.conf.eth0.arp_announce=2
sysctl -w net.ipv4.conf.eth1.arp_announce=2
Arvin:
关闭反向路径过滤
sysctl -w net.ipv4.conf.all.rp_filter=0
sysctl -w net.ipv4.conf.eth0.rp_filter=0
sysctl -w net.ipv4.conf.eth1.rp_filter=0
Arvin:
再配个 重启生效
ip route show table 100
ip rule list