How to put your ns in your prompt

If you spend some time of troubleshooting network namespaces (ns) you will note that sometimes you don't even know if you are inside one, or two, :-P of them.

  • Wouldn't be good if you don't have to paste neutron long network ids to make ns names?
  • Wouldn't be great if your prompt told you in what ns are you?
  • Wouldn't be awesome if you can get into router's namespaces too?

The Solution:

I've created an script called netns which accepts one parameter, the name of of the network or router you want to get into it's namespace.

Also is necessary to modify ~/.bashrc for the user running the command (root most likely).

just add:

PS1='${NETNS:+($NETNS)}${debian_chroot:+($debian_chroot)}\h:\w\$ '

then run:

# netns network-name


# netns router-name