#安装依赖
yum install -y net-tools.x86_64

#查看网卡名称
ifconfig

#4网卡40IP配置
#网卡配置 eth0
vi /etc/sysconfig/network-scripts/ifcfg-eth0

# Created by cloud-init on instance boot automatically, do not edit.
#
BOOTPROTO=static
DEVICE=eth0
HWADDR=52:54:00:e6:d0:43
ONBOOT=yes
PERSISTENT_DHCLIENT=yes
TYPE=Ethernet
USERCTL=no
IPADDR=10.0.4.11
NETMASK=255.255.255.0
GATEWAY=10.0.4.1
IPADDR1=10.0.4.12
NETMASK1=255.255.255.0
GATEWAY1=10.0.4.1
IPADDR2=10.0.4.13
NETMASK2=255.255.255.0
GATEWAY2=10.0.4.1
IPADDR3=10.0.4.14
NETMASK3=255.255.255.0
GATEWAY3=10.0.4.1
IPADDR4=10.0.4.15
NETMASK4=255.255.255.0
GATEWAY4=10.0.4.1
IPADDR5=10.0.4.16
NETMASK5=255.255.255.0
GATEWAY5=10.0.4.1
IPADDR6=10.0.4.17
NETMASK6=255.255.255.0
GATEWAY6=10.0.4.1
IPADDR7=10.0.4.18
NETMASK7=255.255.255.0
GATEWAY7=10.0.4.1
IPADDR8=10.0.4.19
NETMASK8=255.255.255.0
GATEWAY8=10.0.4.1
IPADDR9=10.0.4.20
NETMASK9=255.255.255.0
GATEWAY9=10.0.4.1

#网卡配置 eth1
vi /etc/sysconfig/network-scripts/ifcfg-eth1

# Created by cloud-init on instance boot automatically, do not edit.
#
BOOTPROTO=static
DEVICE=eth1
HWADDR=20:90:6f:16:99:15
ONBOOT=yes
PERSISTENT_DHCLIENT=yes
TYPE=Ethernet
USERCTL=no
IPADDR=10.0.4.21
NETMASK=255.255.255.0
GATEWAY=10.0.4.1
IPADDR1=10.0.4.22
NETMASK1=255.255.255.0
GATEWAY1=10.0.4.1
IPADDR2=10.0.4.23
NETMASK2=255.255.255.0
GATEWAY2=10.0.4.1
IPADDR3=10.0.4.24
NETMASK3=255.255.255.0
GATEWAY3=10.0.4.1
IPADDR4=10.0.4.25
NETMASK4=255.255.255.0
GATEWAY4=10.0.4.1
IPADDR5=10.0.4.26
NETMASK5=255.255.255.0
GATEWAY5=10.0.4.1
IPADDR6=10.0.4.27
NETMASK6=255.255.255.0
GATEWAY6=10.0.4.1
IPADDR7=10.0.4.28
NETMASK7=255.255.255.0
GATEWAY7=10.0.4.1
IPADDR8=10.0.4.29
NETMASK8=255.255.255.0
GATEWAY8=10.0.4.1
IPADDR9=10.0.4.30
NETMASK9=255.255.255.0
GATEWAY9=10.0.4.1

#网卡配置 eth2
vi /etc/sysconfig/network-scripts/ifcfg-eth2

# Created by cloud-init on instance boot automatically, do not edit.
#
BOOTPROTO=static
DEVICE=eth2
HWADDR=20:90:6f:49:30:f7
ONBOOT=yes
PERSISTENT_DHCLIENT=yes
TYPE=Ethernet
USERCTL=no
IPADDR=10.0.4.31
NETMASK=255.255.255.0
GATEWAY=10.0.4.1
IPADDR1=10.0.4.32
NETMASK1=255.255.255.0
GATEWAY1=10.0.4.1
IPADDR2=10.0.4.33
NETMASK2=255.255.255.0
GATEWAY2=10.0.4.1
IPADDR3=10.0.4.34
NETMASK3=255.255.255.0
GATEWAY3=10.0.4.1
IPADDR4=10.0.4.35
NETMASK4=255.255.255.0
GATEWAY4=10.0.4.1
IPADDR5=10.0.4.36
NETMASK5=255.255.255.0
GATEWAY5=10.0.4.1
IPADDR6=10.0.4.37
NETMASK6=255.255.255.0
GATEWAY6=10.0.4.1
IPADDR7=10.0.4.38
NETMASK7=255.255.255.0
GATEWAY7=10.0.4.1
IPADDR8=10.0.4.39
NETMASK8=255.255.255.0
GATEWAY8=10.0.4.1
IPADDR9=10.0.4.40
NETMASK9=255.255.255.0
GATEWAY9=10.0.4.1

#网卡配置 eth3
vi /etc/sysconfig/network-scripts/ifcfg-eth3

# Created by cloud-init on instance boot automatically, do not edit.
#
BOOTPROTO=static
DEVICE=eth3
HWADDR=20:90:6f:9e:ea:c3
ONBOOT=yes
PERSISTENT_DHCLIENT=yes
TYPE=Ethernet
USERCTL=no
IPADDR=10.0.4.41
NETMASK=255.255.255.0
GATEWAY=10.0.4.1
IPADDR1=10.0.4.42
NETMASK1=255.255.255.0
GATEWAY1=10.0.4.1
IPADDR2=10.0.4.43
NETMASK2=255.255.255.0
GATEWAY2=10.0.4.1
IPADDR3=10.0.4.44
NETMASK3=255.255.255.0
GATEWAY3=10.0.4.1
IPADDR4=10.0.4.45
NETMASK4=255.255.255.0
GATEWAY4=10.0.4.1
IPADDR5=10.0.4.46
NETMASK5=255.255.255.0
GATEWAY5=10.0.4.1
IPADDR6=10.0.4.47
NETMASK6=255.255.255.0
GATEWAY6=10.0.4.1
IPADDR7=10.0.4.48
NETMASK7=255.255.255.0
GATEWAY7=10.0.4.1
IPADDR8=10.0.4.49
NETMASK8=255.255.255.0
GATEWAY8=10.0.4.1
IPADDR9=10.0.4.50
NETMASK9=255.255.255.0
GATEWAY9=10.0.4.1

#关闭反向过滤。
vi /etc/sysctl.conf
#查找 net.ipv4.conf.default.rp_filter = 1(大约16行的位置)
#修改为
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
net.ipv4.conf.eth2.rp_filter = 0
net.ipv4.conf.eth3.rp_filter = 0

#重启网络
systemctl restart network

#配置策略路由,让报文从哪个网卡进,并从该网卡返回。
#创建4张路由表
echo "10 t1" >> /etc/iproute2/rt_tables
echo "20 t2" >> /etc/iproute2/rt_tables
echo "30 t3" >> /etc/iproute2/rt_tables
echo "40 t4" >> /etc/iproute2/rt_tables

#给4个路由表添加默认路由,10.0.4.1为网关
vi /etc/sysconfig/network-scripts/route-eth0
default dev eth0 via 10.0.4.1 table 10
vi /etc/sysconfig/network-scripts/route-eth1
default dev eth1 via 10.0.4.1 table 20
vi /etc/sysconfig/network-scripts/route-eth2
default dev eth2 via 10.0.4.1 table 30
vi /etc/sysconfig/network-scripts/route-eth3
default dev eth3 via 10.0.4.1 table 40

#配置策略路由
echo "ip rule add from 10.0.4.11 table 10" >> /etc/rc.d/rc.local
echo "ip rule add from 10.0.4.12 table 10" >> /etc/rc.d/rc.local
echo "ip rule add from 10.0.4.13 table 10" >> /etc/rc.d/rc.local
echo "ip rule add from 10.0.4.14 table 10" >> /etc/rc.d/rc.local
echo "ip rule add from 10.0.4.15 table 10" >> /etc/rc.d/rc.local
echo "ip rule add from 10.0.4.16 table 10" >> /etc/rc.d/rc.local
echo "ip rule add from 10.0.4.17 table 10" >> /etc/rc.d/rc.local
echo "ip rule add from 10.0.4.18 table 10" >> /etc/rc.d/rc.local
echo "ip rule add from 10.0.4.19 table 10" >> /etc/rc.d/rc.local
echo "ip rule add from 10.0.4.20 table 10" >> /etc/rc.d/rc.local
echo "ip rule add from 10.0.4.21 table 20" >> /etc/rc.d/rc.local
echo "ip rule add from 10.0.4.22 table 20" >> /etc/rc.d/rc.local
echo "ip rule add from 10.0.4.23 table 20" >> /etc/rc.d/rc.local
echo "ip rule add from 10.0.4.24 table 20" >> /etc/rc.d/rc.local
echo "ip rule add from 10.0.4.25 table 20" >> /etc/rc.d/rc.local
echo "ip rule add from 10.0.4.26 table 20" >> /etc/rc.d/rc.local
echo "ip rule add from 10.0.4.27 table 20" >> /etc/rc.d/rc.local
echo "ip rule add from 10.0.4.28 table 20" >> /etc/rc.d/rc.local
echo "ip rule add from 10.0.4.29 table 20" >> /etc/rc.d/rc.local
echo "ip rule add from 10.0.4.30 table 20" >> /etc/rc.d/rc.local
echo "ip rule add from 10.0.4.31 table 30" >> /etc/rc.d/rc.local
echo "ip rule add from 10.0.4.32 table 30" >> /etc/rc.d/rc.local
echo "ip rule add from 10.0.4.33 table 30" >> /etc/rc.d/rc.local
echo "ip rule add from 10.0.4.34 table 30" >> /etc/rc.d/rc.local
echo "ip rule add from 10.0.4.35 table 30" >> /etc/rc.d/rc.local
echo "ip rule add from 10.0.4.36 table 30" >> /etc/rc.d/rc.local
echo "ip rule add from 10.0.4.37 table 30" >> /etc/rc.d/rc.local
echo "ip rule add from 10.0.4.38 table 30" >> /etc/rc.d/rc.local
echo "ip rule add from 10.0.4.39 table 30" >> /etc/rc.d/rc.local
echo "ip rule add from 10.0.4.40 table 30" >> /etc/rc.d/rc.local
echo "ip rule add from 10.0.4.41 table 40" >> /etc/rc.d/rc.local
echo "ip rule add from 10.0.4.42 table 40" >> /etc/rc.d/rc.local
echo "ip rule add from 10.0.4.43 table 40" >> /etc/rc.d/rc.local
echo "ip rule add from 10.0.4.44 table 40" >> /etc/rc.d/rc.local
echo "ip rule add from 10.0.4.45 table 40" >> /etc/rc.d/rc.local
echo "ip rule add from 10.0.4.46 table 40" >> /etc/rc.d/rc.local
echo "ip rule add from 10.0.4.47 table 40" >> /etc/rc.d/rc.local
echo "ip rule add from 10.0.4.48 table 40" >> /etc/rc.d/rc.local
echo "ip rule add from 10.0.4.49 table 40" >> /etc/rc.d/rc.local
echo "ip rule add from 10.0.4.50 table 40" >> /etc/rc.d/rc.local
chmod +x /etc/rc.d/rc.local

#重启网络
systemctl restart network
Last modification:June 9, 2023
如果觉得我的文章对你有用,请随意赞赏