1

The solution to non-virtual network interfaces is here: https://unix.stackexchange.com/a/210992

But the problem is I have multiple IPs on one network interface and I'd like to be able to assign each IP to a different application.

For example, I have eth0:0, eth0:1, etc.

When I do command(note the virtual interface):

ip link set eth0:0 netns test_ns

It takes eth0 ip and not eth0:0.. it also takes away the entire interface and I can't connect to it from a public source.

Is there a way to use virtual network interface for different processes while having the server accessible from a public source?

sojim2
  • 143

1 Answers1

1

Interface names like eth0:0 do not denote distinct interfaces ('virtual or not), but are aliases for the same interface. The aliases are only needed because old deprecated tools like ifconfig can't assign several addresses using the same interface name.

EDIT: You can connect two network namespaces with a veth interface pair.

sudo ip link add ns1_eth type veth peer name veth0

Move the other end to the ns1 netspace:

sudo ip link set ns1_eth netns ns1

The vethpair works like tube, what you send on one end will appear on the other end. You will also need to set up addressing and routing in addition to the commands above.

Johan Myréen
  • 13,168
  • How can I set multiple netns on multiple IPs on one interface? Is it possible? – sojim2 Jan 26 '18 at 06:32
  • 1
    For those who's unfamiliar with veth, check this link on how to set it up: https://superuser.com/a/765078/698848 – sojim2 Jan 26 '18 at 17:54