Network namespace, ssh, X11

I was on a similar situation, here is how I work around it.

Some background: I had to span several selenium Firefox instances within namespaces for binding them with different IP addresses. But as you know I was having the error:

Error: Can't open display: localhost:10.0

Instead of working with unix sockets as Marius suggested I have just bound SSHD X11Forwarding to * instead of localhost (adding "X11UseLocalhost no" to the config) and redirected simple TCP connections with socat.

Attention to the security consequences of doing this!!!!

After this change on sshd, the DISPLAY will automatically change when you login from this:

 DISPLAY=localhost:10.0

To something like:

 DISPLAY=10.0.0.1:10.0

After that I just have to do redirect the :

ip netns exec my-NNS socat tcp-listen:6010,reuseaddr,fork tcp:192.168.5.130:6010 &

Then you should be able to work with xeyes, firefox, x-whatever-you-want...:

ip netns exec my-NNS xeyes &

And voilà!