Ubuntu服务器:多个VLAN、虚拟端口和转发

Ubuntu服务器:多个VLAN、虚拟端口和转发,ubuntu,iptables,portforwarding,ports,iproute,Ubuntu,Iptables,Portforwarding,Ports,Iproute,我在2个VLAN中有4个IP地址。 我需要用不同的地址从Ubuntu服务器出来: curl --interface '<IP ADDRESS>' ifconfig.co 2) 在/etc/iproute2/rt_表中创建路由表。在文件末尾添加: 1 rt0 2 rt1 3) 之后,运行以下命令: sysctl -w net.ipv4.conf.eno1.rp_filter=0 sysctl -w net.ipv4.conf.tun0.rp_filter=0 sysctl -w n

我在2个VLAN中有4个IP地址。 我需要用不同的地址从Ubuntu服务器出来:

curl --interface '<IP ADDRESS>' ifconfig.co
2) 在/etc/iproute2/rt_表中创建路由表。在文件末尾添加:

1 rt0
2 rt1
3) 之后,运行以下命令:

sysctl -w net.ipv4.conf.eno1.rp_filter=0
sysctl -w net.ipv4.conf.tun0.rp_filter=0
sysctl -w net.ipv4.conf.all.rp_filter=0
sysctl -w net.ipv4.conf.default.rp_filter=0
sysctl -w net.ipv4.conf.lo.rp_filter=0

sysctl -w net.ipv4.conf.all.forwarding=1
sysctl -w net.ipv4.conf.default.forwarding=1
sysctl -w net.ipv4.conf.eno1.forwarding=1
sysctl -w net.ipv4.conf.lo.forwarding=1
sysctl -w net.ipv4.conf.tun0.forwarding=1

sysctl -w net.ipv6.conf.all.forwarding=1
sysctl -w net.ipv6.conf.default.forwarding=1
sysctl -w net.ipv6.conf.eno1.forwarding=1
sysctl -w net.ipv6.conf.lo.forwarding=1
sysctl -w net.ipv6.conf.tun0.forwarding=1

sysctl -w net.ipv4.tcp_fwmark_accept=1

iptables --table nat --append POSTROUTING -j MASQUERADE

iptables -t mangle -A OUTPUT -s 175.176.95.0/24 -j MARK --set-mark 1
iptables -t mangle -A OUTPUT -s 175.176.96.0/24 -j MARK --set-mark 2

iptables -t nat -I POSTROUTING -o eno1 -s 175.176.95.119 -j SNAT --to-source 175.176.95.119
iptables -t nat -I POSTROUTING -o eno1 -s 175.176.95.120 -j SNAT --to-source 175.176.95.120

iptables -t nat -I POSTROUTING -o eno1 -s 175.176.96.119 -j SNAT --to-source 175.176.96.119
iptables -t nat -I POSTROUTING -o eno1 -s 175.176.96.120 -j SNAT --to-source 175.176.96.120

ip route add 175.176.95.0/24 dev eno1.155 src 175.176.95.119 table rt0
ip route add default via 175.176.95.1 dev eno1.155 table rt0

ip route add 175.176.96.0/24 dev eno1.156 src 175.176.96.119 table rt1
ip route add default via 175.176.96.1 dev eno1.156 table rt1

ip rule add from all fwmark 1 lookup rt0
ip rule add from all fwmark 2 lookup rt1
当我尝试时: curl——接口“175.176.95.119”ifconfig.co 它起作用了。当我尝试时: curl——接口“175.176.95.120”ifconfig.co 它起作用了。 但是地址为175.176.96.119和175.176.96.120时,它不起作用

我能做些什么才能使用175.176.96.119和175.176.96.120? 谢谢

sysctl -w net.ipv4.conf.eno1.rp_filter=0
sysctl -w net.ipv4.conf.tun0.rp_filter=0
sysctl -w net.ipv4.conf.all.rp_filter=0
sysctl -w net.ipv4.conf.default.rp_filter=0
sysctl -w net.ipv4.conf.lo.rp_filter=0

sysctl -w net.ipv4.conf.all.forwarding=1
sysctl -w net.ipv4.conf.default.forwarding=1
sysctl -w net.ipv4.conf.eno1.forwarding=1
sysctl -w net.ipv4.conf.lo.forwarding=1
sysctl -w net.ipv4.conf.tun0.forwarding=1

sysctl -w net.ipv6.conf.all.forwarding=1
sysctl -w net.ipv6.conf.default.forwarding=1
sysctl -w net.ipv6.conf.eno1.forwarding=1
sysctl -w net.ipv6.conf.lo.forwarding=1
sysctl -w net.ipv6.conf.tun0.forwarding=1

sysctl -w net.ipv4.tcp_fwmark_accept=1

iptables --table nat --append POSTROUTING -j MASQUERADE

iptables -t mangle -A OUTPUT -s 175.176.95.0/24 -j MARK --set-mark 1
iptables -t mangle -A OUTPUT -s 175.176.96.0/24 -j MARK --set-mark 2

iptables -t nat -I POSTROUTING -o eno1 -s 175.176.95.119 -j SNAT --to-source 175.176.95.119
iptables -t nat -I POSTROUTING -o eno1 -s 175.176.95.120 -j SNAT --to-source 175.176.95.120

iptables -t nat -I POSTROUTING -o eno1 -s 175.176.96.119 -j SNAT --to-source 175.176.96.119
iptables -t nat -I POSTROUTING -o eno1 -s 175.176.96.120 -j SNAT --to-source 175.176.96.120

ip route add 175.176.95.0/24 dev eno1.155 src 175.176.95.119 table rt0
ip route add default via 175.176.95.1 dev eno1.155 table rt0

ip route add 175.176.96.0/24 dev eno1.156 src 175.176.96.119 table rt1
ip route add default via 175.176.96.1 dev eno1.156 table rt1

ip rule add from all fwmark 1 lookup rt0
ip rule add from all fwmark 2 lookup rt1