0

My VPS provider assigned 4 IPv4 to my vps. However, This assigned to single NIC, and VLAN not working(Maybe it is my configuration problem). If I try using VLAN, I can't get external network using VLAN interface.

I want run same Java application on each IP address. This application serving image cache server and notify own IP address to Master server to send HTTP request, and master server get IP from HTTP Request IP.

So, I need to force use specify IP to connect external network for each Java process.

When I tried netns using below configuration, app0_ns works perfectly, but not others. They can ping to 10.200.0.0/16, but can't access to external network.

Here command that I tried to make netns.

My vps using Ubuntu 18.04, and I can change the OS version.

ip netns add app0_ns
ip netns add app1_ns
ip netns add app2_ns
ip netns add app3_ns

ip link add v_app0a type veth peer name v_app0b
ip link add v_app1a type veth peer name v_app1b
ip link add v_app2a type veth peer name v_app2b
ip link add v_app3a type veth peer name v_app3b

ip link set v_app0b netns app0_ns
ip link set v_app1b netns app1_ns
ip link set v_app2b netns app2_ns
ip link set v_app3b netns app3_ns

ip addr add 10.200.0.1/24 dev v_app0a
ip link set v_app0a up
ip addr add 10.200.1.1/24 dev v_app1a
ip link set v_app1a up
ip addr add 10.200.2.1/24 dev v_app2a
ip link set v_app2a up
ip addr add 10.200.3.1/24 dev v_app3a
ip link set v_app3a up

ip netns exec app0_ns ip addr add 10.200.0.2/24 dev v_app0b
ip netns exec app0_ns ip link set v_app0b up
ip netns exec app0_ns ip link set lo up
ip netns exec app0_ns ip route add default via 10.200.0.1

ip netns exec app1_ns ip addr add 10.200.1.2/24 dev v_app1b
ip netns exec app1_ns ip link set v_app1b up
ip netns exec app1_ns ip link set lo up
ip netns exec app1_ns ip route add default via 10.200.1.1

ip netns exec app2_ns ip addr add 10.200.2.2/24 dev v_app2b
ip netns exec app2_ns ip link set v_app2b up
ip netns exec app2_ns ip link set lo up
ip netns exec app2_ns ip route add default via 10.200.2.1

ip netns exec app3_ns ip addr add 10.200.3.2/24 dev v_app3b
ip netns exec app3_ns ip link set v_app3b up
ip netns exec app3_ns ip link set lo up
ip netns exec app3_ns ip route add default via 10.200.3.1

iptables -t nat -A POSTROUTING -s 10.200.0.1/24 -o eth0 -j MASQUERADE
iptables -t nat -A POSTROUTING -s 10.200.1.1/24 -o eth0:1 -j MASQUERADE
iptables -t nat -A POSTROUTING -s 10.200.2.1/24 -o eth0:2 -j MASQUERADE
iptables -t nat -A POSTROUTING -s 10.200.3.1/24 -o eth0:3 -j MASQUERADE

iptables -A FORWARD -i eth0 -o v_app0a -j ACCEPT
iptables -A FORWARD -o eth0 -i v_app0a -j ACCEPT
iptables -A FORWARD -i eth0:1 -o v_app1a -j ACCEPT
iptables -A FORWARD -o eth0:1 -i v_app1a -j ACCEPT
iptables -A FORWARD -i eth0:2 -o v_app2a -j ACCEPT
iptables -A FORWARD -o eth0:2 -i v_app2a -j ACCEPT
iptables -A FORWARD -i eth0:3 -o v_app3a -j ACCEPT
iptables -A FORWARD -o eth0:3 -i v_app3a -j ACCEPT

Here my /etc/network/interfaces.

 auto lo
  iface lo inet loopback

 auto eth0
  iface eth0 inet static
   address [Removed]
   gateway [Removed]
   netmask 255.255.255.0
   dns-nameservers 8.8.8.8 8.8.4.4
   up ip addr add [Removed]/48 dev eth0
   up ip -6 route add [Removed] dev eth0
   up ip -6 route add default via [Removed]

 auto eth0:1
  iface eth0:1 inet static
   address [Removed]
   gateway [Removed]
   netmask 255.255.255.0
   dns-nameservers 8.8.8.8 8.8.4.4

 auto eth0.2
  iface eth0.2 inet static
   address [Removed]
   gateway [Removed]
   netmask 255.255.255.0
   dns-nameservers 8.8.8.8 8.8.4.4
   vlan-raw-device eth0

 auto eth0:3
  iface eth0:3 inet static
   address [Removed]
   gateway [Removed]
   netmask 255.255.255.0
   dns-nameservers 8.8.8.8 8.8.4.4

Here I tried VLAN configuration.

 auto eth0.3
  iface eth0.3 inet static
   address [Removed]
   gateway [Removed]
   netmask 255.255.255.0
   dns-nameservers 8.8.8.8 8.8.4.4
   vlan-raw-device eth0
Hoto Cocoa
  • 113
  • 6

1 Answers1

0

It resolved. I used SNAT.

Virtual Interfaces is "Virtual" so It can't resolved as Interface name. I have to using just Physical Interface name.

Here's an example for future reference.

iptables -t nat -A POSTROUTING -s 10.200.0.1/24 -o eth0 -j SNAT --to (eth0 IP)
iptables -t nat -A POSTROUTING -s 10.200.1.1/24 -o eth0 -j SNAT --to (eth0:1 IP)
iptables -t nat -A POSTROUTING -s 10.200.2.1/24 -o eth0 -j SNAT --to (eth0:2 IP)
iptables -t nat -A POSTROUTING -s 10.200.3.1/24 -o eth0 -j SNAT --to (eth0:3 IP)
Hoto Cocoa
  • 113
  • 6