Custom Search

SUBSCRIBE

SUBSCRIBE : 300 + Free Video Tutorials Programming (Python, golang, Julia), DevOps

Thursday, July 17, 2014

How to Create a network namespace and run a simple web server in it

1)
Add a namespace

#sudo ip netns add myns1

2)
List all namespaces

#ip netns list

3)
Execute commands in a namespace

#sudo ip netns exec myns1 your-command

4)
Check all the interfaces and their IP in the namespace myns1

#sudo ip netns exec myns1 ifconfig -a
#sudo ip netns exec myns1 ip link list


5)
The default interface "lo" in the namespace myns1 doesn't have any IP. So set it like.

#sudo ip netns exec myns1 ifconfig lo 127.0.0.1 up
#sudo ip netns exec myns1 ifconfig -a


6)
Create an index.html

#vim index.html

7)
Run a simple web server on port 80, in namespace "myns1", using netcat command.

#sudo ip netns exec myns1 netcat -l 80 < index.html

8)
Access your webserver from the same namespace "myns1"

#sudo ip netns exec myns1 wget http://127.0.0.1:80

2 comments:

  1. http://blog.scottlowe.org/2013/09/04/introducing-linux-network-namespaces/

    ReplyDelete
  2. https://www.digitalocean.com/community/tutorials/how-to-use-netcat-to-establish-and-test-tcp-and-udp-connections-on-a-vps

    ReplyDelete