I have a Debian Stretch VPS with 4 IPv4 addresses. I want to run several programs, binding them to specific IP addresses (To make outgoing HTTP requests from different IP's). So for example command
~$ curl icanhazip.com
would output specific different IP's.
What I've done:
0) Ordered extra IP's from my ISP
1) Edited /etc/network/interfaces and added extra IP's:
# Initial configuration after ordering VPS
source /etc/network/interfaces.d/*
auto lo
iface lo inet loopback
allow-hotplug ens3
iface ens3 inet static
address 194.67.205.100
netmask 255.255.252.0
gateway 194.67.204.1
# Next lines were added by me
auto ens3:1
iface ens3:1 inet static
address 185.125.216.101
netmask 255.255.252.0
auto ens3:2
iface ens3:2 inet static
address 185.125.216.102
netmask 255.255.252.0
auto ens3:3
iface ens3:3 inet static
address 185.125.216.103
netmask 255.255.252.0
2) Then I've created netns for each IP
ip netns add ns1
ip netns add ns2
and so on
3) Tried to add interface to newly created netns:
# ip link set ens3:1 netns ns1
4) At that moment SSH connection drops. If I login using VNC, and execute ip a
, I see that the whole physical interface ens3 and all its subinterfaces disappeared from main netns.
Command output screenshot
Wnat am I doing wrong? How can I bind programs to different source IP addresses?
P.S. I am developing a simple site scraper using Python, need different IP's to speed up parsing (making more requests per second) and avoid ban.