我在2个VLAN中有4个IP地址。 我需要从不同地址的Ubuntu服务器出去:
curl --interface '<IP ADDRESS>' ifconfig.co
所有VLAN都通过一个网卡中的一根以太网电缆提供。
我在做什么:
1)这是我的/ etc / network / interfaces
auto eno1.155
iface eno1.155 inet static
address 175.176.95.119
netmask 255.255.255.0
gateway 175.176.95.1
dns-nameservers 175.176.90.254 175.176.90.253
vlan-raw-device eno1
auto eno1.155:0
iface eno1.155:0 inet static
address 175.176.95.120
netmask 255.255.255.0
gateway 175.176.95.1
dns-nameservers 175.176.90.254 175.176.90.253
vlan-raw-device eno1
auto eno1.156
iface eno1.156 inet static
address 175.176.96.119
netmask 255.255.255.0
gateway 175.176.96.1
dns-nameservers 175.176.90.254 175.176.90.253
vlan-raw-device eno1
auto eno1.156:0
iface eno1.156:0 inet static
address 175.176.96.120
netmask 255.255.255.0
gateway 175.176.96.1
dns-nameservers 175.176.90.254 175.176.90.253
vlan-raw-device eno1
2)在/ etc / iproute2 / rt_tables中创建路由表。添加到文件的末尾:
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 --interface'175.176.95.119'ifconfig.co 有用。当我尝试时: curl --interface'175.176.95.120'ifconfig.co 有用。 但是地址:175.176.96.119和175.176.96.120它不起作用。
如何才能使用175.176.96.119和175.176.96.120? 谢谢!