0

I'm running an Ubuntu server VPS with Docker image containers, which provides me 2 external IPv4 addresses within the interface venet0. venet0 has got 2 sub v-interfaces: venet0:0 and venet0:1 (each with different IPv4 address);

is it possible that each docker image will use different venet? and then it will have different IPv4 for in/out traffic ?

ifconfig:

docker0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 172.17.0.1 netmask 255.255.0.0 broadcast 172.17.255.255 ether 02:42:6e:1b:78:dd txqueuelen 0 (Ethernet) RX packets 300 bytes 40314 (40.3 KB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 279 bytes 155791 (155.7 KB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 loop txqueuelen 1000 (Local Loopback) RX packets 0 bytes 0 (0.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 0 bytes 0 (0.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

venet0: flags=211<UP,BROADCAST,POINTOPOINT,RUNNING,NOARP> mtu 1500 inet 127.0.0.1 netmask 255.255.255.255 broadcast 0.0.0.0 destination 127.0.0.1 unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00 txqueuelen 0 (UNSPEC) RX packets 2535 bytes 280255 (280.2 KB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 3514 bytes 368638 (368.6 KB) TX errors 0 dropped 1 overruns 0 carrier 0 collisions 0

venet0:0: flags=211<UP,BROADCAST,POINTOPOINT,RUNNING,NOARP> mtu 1500 inet xx.xx.xx.xx netmask 255.255.255.0 broadcast xx.xx.xx.xx destination xx.xx.xx.xx unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00 txqueuelen 0 (UNSPEC)

venet0:1: flags=211<UP,BROADCAST,POINTOPOINT,RUNNING,NOARP> mtu 1500 inet xx.yy.yy.yy netmask 255.255.255.0 broadcast xx.yy.yy.yy destination xx.yy.yy.yy unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00 txqueuelen 0 (UNSPEC)

veth3e60e5d: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 ether fe:73:1e:7d:30:0a txqueuelen 0 (Ethernet) RX packets 0 bytes 0 (0.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 6 bytes 252 (252.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

veth83488a2: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 ether 0e:11:e7:a6:8d:47 txqueuelen 0 (Ethernet) RX packets 300 bytes 44514 (44.5 KB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 279 bytes 155791 (155.7 KB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

ip link:

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 2: venet0: <BROADCAST,POINTOPOINT,NOARP,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN mode DEFAULT group default link/void 3: docker0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT group default link/ether 02:42:6e:1b:78:dd brd ff:ff:ff:ff:ff:ff 5: veth3e60e5d@if4: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master docker0 state UP mode DEFAULT group default link/ether fe:73:1e:7d:30:0a brd ff:ff:ff:ff:ff:ff link-netnsid 0 7: veth83488a2@if6: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master docker0 state UP mode DEFAULT group default link/ether 0e:11:e7:a6:8d:47 brd ff:ff:ff:ff:ff:ff link-netnsid 1

1 Answer 1

0

The solution that I have found and it is working properly is:

# Step 1
# Creating 2 different local networks (nw1 & nw2)
# and then route it via the desired IP addresses
sudo docker network create --driver bridge --subnet=172.18.0.2/16 --ip-range=172.18.0.2/16 nw1
sudo iptables -t nat -I POSTROUTING -p all -s 172.18.0.2/16 ! -o bridge -j SNAT --to-source FIRST_IPv4

sudo docker network create --driver bridge --subnet=172.19.0.2/16 --ip-range=172.19.0.2/16 nw2
sudo iptables -t nat -I POSTROUTING -p all -s 172.19.0.2/16 ! -o bridge -j SNAT --to-source SECOND_IPv4



# Step 2
# run the docker with '--net'
docker run -dt --name my_docker_name1 --net=nw1--restart=unless-stopped docker_image_name
docker run -dt --name my_docker_name2 --net=nw2--restart=unless-stopped docker_image_name
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.