Based on @olivervbk answer below is my!
Run all commands as "root".
Use the command...
ip a
... to find out the name of the network interface you will want to use.
Run the commands below as the template...
ip netns add [INTERFACE_NAME]_ns
ip link set dev [INTERFACE_NAME] netns [INTERFACE_NAME]_ns
ip netns exec [INTERFACE_NAME]_ns ifconfig [INTERFACE_NAME] 10.1.1.10/24 up
ip netns exec [INTERFACE_NAME]_ns ifconfig lo 127.0.0.1/8 up
ip netns exec [INTERFACE_NAME]_ns route add default gw 10.1.1.1
ip netns exec [INTERFACE_NAME]_ns dhcpcd [INTERFACE_NAME]
ip netns exec [INTERFACE_NAME]_ns sudo -b -u [YOUR_USER] [APP_NAME] 2> /dev/null 1> /dev/null &
- [INTERFACE_NAME] - Replace with the name of the chosen network interface.
- [YOUR_USER] - Replace with your user name.
- [APP_NAME] - Name of the application that will be executed in the namespace "[INTERFACE_NAME]_ns". Eg.: "firefox".
NOTE I: The "-b -u" flags in the "sudo" command allow the application to run using your user (not "root") and in the background releasing the terminal. The 2> /dev/null 1> /dev/null &
snippet is to prevent outputs from "[APP_NAME]" being printed at the terminal.
NOTE II: The values of ip "10.1.1.10" and "10.1.1.1" are arbitrary.
NOTE III: To work for me I had to run the dhcpcd [INTERFACE_NAME]
command.
To remove the namespace use...
ip netns del [INTERFACE_NAME]_ns
... or...
ip -all netns delete
... to remove any that exists.
clients use bind/connect as well, look at the bind.c.txt documentation of how to force ircII (an irc-client programm) to a given ip: 'Example in bash to use your virtual IP as your outgoing sourceaddress for ircII: BIND_ADDR="your-virt-ip" LD_PRELOAD=./bind.so ircII' – akira – 2011-02-03T13:34:08.903
I found a different approach here, I hope it's helpful (I sure hope the described kernel policy routing is enabled by default nowadays): http://kindlund.wordpress.com/2007/11/19/configuring-multiple-default-routes-in-linux/
– Savvas Radevic – 2012-01-28T23:52:48.407