Bind programs to a specific network interface attachment
mouse 277 · person cloud · link
Last update
2018-02-16
2018
02-16
«eg: encapsualte vpn in a netns»
1
2
3
4
5
6
7
8
9
10
11
12
13
# create a new network namespace:
ip netns add test_ns

# exclusively assign an interface to the namespace
ip link set eth0 netns test_ns

# run commans inside the namespace:
ip netns exec test_ns    ip link set eth0 up  # bring up interface
ip netns exec test_ns    dhclient eth0        # assign IP via dhcp

# test network in the namespace
ip netns exec test_ns    ping www.google.com
ip netns exec test_ns    firefox

Source: Stackexchange, ip netns manpage

See also: SuperUser, LD_PRELOAD fix via bind.c