title: How to use Linux Network Namespaces for per processes routing?
body: <p>I want to crawl webpages through browser and store network traffic per URL (not only HTTP but also udp, rtmp etc.) I came across this solution to use linux network namespace for per process routing. Following are the steps I followed, however unable to browse the webpage.</p>
  
  <pre><code>ip netns add test
  </code></pre>
  
  <p>create a pair of virtual network interfaces (veth-a and veth-b):</p>
  
  <pre><code>ip link add veth-a type veth peer name veth-b
  </code></pre>
  
  <p>change the active namespace of the veth-a interface:</p>
  
  <pre><code>ip link set veth-a netns test
  </code></pre>
  
  <p>configure the IP addresses of the virtual interfaces:</p>
  
  <pre><code>ip netns exec test ifconfig veth-a up 192.168.163.1 netmask 255.255.255.0
  
  ifconfig veth-b up 192.168.163.254 netmask 255.255.255.0
  </code></pre>
  
  <p>configure the routing in the test namespace:</p>
  
  <pre><code>ip netns exec test route add default gw 192.168.163.254 dev veth-a
  
  sudo bash -c ‘echo 1 &gt; /proc/sys/net/ipv4/ip_forward’
  
  sudo iptables -t nat -A POSTROUTING -s 192.168.163.0/24 -o wlan0 -j MASQUERADE
  </code></pre>
  
  <p>Open Browser in the namepace and get following:</p>
  
  <pre><code>sudo ip netns exec test /usr/bin/firefox http://google.com
  </code></pre>
  
  <p>(firefox:15861): GConf-WARNING **: Client failed to connect to the D-BUS daemon:
  Failed to connect to socket /tmp/dbus-xE8M4KnMPn: Connection refused</p>
  
  <p>(firefox:15861): LIBDBUSMENU-GLIB-WARNING **: Unable to get session bus: Could not connect: Connection refused</p>
  
  <p>In wireshark: <code>sudo ip netns exec test wireshark</code>
  I can see Only Outgoing DNS requests from 192.168.163 to 127.0.1.1.
  Kindly let me know what I am missing here?</p>