ifconfig
主 Ip
ens4: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1460
inet 10.168.0.7 netmask 255.255.255.255 broadcast 10.168.0.7
副 ip
ens5: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1460
inet 10.120.0.5 netmask 255.255.255.255 broadcast 10.120.0.5
配置路由
echo "1 rt1" | sudo tee -a /etc/iproute2/rt_tables
ip route add 10.120.0.1 src 10.120.0.5 dev ens5 table rt1
ip route add default via 10.120.0.1 dev ens5 table rt1
ip rule add from 10.120.0.5/20 table rt1
ip rule add to 10.120.0.5/20 table rt1
docker network create network1 --driver bridge --subnet 192.168.33.0/24
docker network create network2 --driver bridge --subnet 192.168.34.0/24
iptables -t nat -I POSTROUTING -s 192.168.33.0/24 -j SNAT --to-source 10.168.0.7
iptables -t nat -I POSTROUTING -s 192.168.34.0/24 -j SNAT --to-source 10.120.0.5
docker run -d --network network1 --name tm1 <Container Name>
docker run -d --network network2 --name tm2 <Container Name>
1
ftfunjth 2023-06-05 19:57:05 +08:00
echo "1 rt1" | sudo tee -a /etc/iproute2/rt_tables
echo "2 rt2" | sudo tee -a /etc/iproute2/rt_tables ip rule add from 192.168.33.0/24 table rt1 ip rule add from 192.168.34.0/24 table rt2 ip route add default via 10.168.0.7 ens4 table rt1 ip route add default via 10.120.0.5 ens5 table rt2 docker network create network1 --driver bridge --subnet 192.168.33.0/24 docker network create network2 --driver bridge --subnet 192.168.34.0/24 docker run -d --network network1 --name tm1 <Container Name> docker run -d --network network2 --name tm2 <Container Name> |
2
fangwenxue OP @ftfunjth 不好使
|