Tuesday, August 15, 2017

Per process routing using net name space netns

** info
- name space to be created called netns1
- interface inside namespace called veth1
- interface outside namespace called veth0

$ sudo ip netns add netns1

$ sudo ip link add veth0 type veth peer name veth1
$ sudo ip link set veth1 netns netns1


1- set ip for both interface
$ sudo ip netns exec netns1 ifconfig veth1 192.168.100.2/24 up
$ sudo ifconfig veth0 192.168.100.2/24 up



now the host and name space  can communicate with the ip

2- to skip the host route table, we should add veth0 as the bridge to another interface,

$ brctl addbr br0
$ brctl addif eth0 veth0

now we can add default route inside the namespace and route directly to the interface

$ sudo ip netns exec netns1 ip route add default via another_gw_ip 

- execute the application
$ sudo ip netns exec netns1 ping 8.8.8.8

or to get the bash shell
$ sudo ip netns exec netns1 bath




*** tips
- add loopback interface
$ ip netns exec netns1 ip link set dev lo up

- list available name space being created
$ ip netns exec netns1 ip link list

No comments:

Post a Comment