X Forwarding with IPv6 disabled on Ubuntu

So far I haven’t had a chance to really learn and understand IPv6, so as I’ve built new boxes I have disabled IPv6 explicitely. On Ubuntu, you can do this by adding these three lines to /etc/sysctl.conf and then rebooting:

net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
net.ipv6.conf.lo.disable_ipv6 = 1

Voila! No more IPv6 in ifconfig.

root@bt:~# ifconfig
eth0      Link encap:Ethernet  HWaddr 58:12:d5:c1:f8:a9
          inet addr:192.168.1.2  Bcast:192.168.1.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:3268 errors:0 dropped:0 overruns:0 frame:0
          TX packets:2110 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:4156770 (4.1 MB)  TX bytes:191688 (191.6 KB)
          Interrupt:50

However, SSH has an issue where if IPv6 is disabled, it still attempts to listen on an IPv6 address, which in turn breaks X forwarding for some reason. You get an “Error: display not set” when you attempt to launch an X application. Setting DISPLAY manually does not work.

Here you can see SSH is trying to listen on tcp6 even though IPv6 is off:

root@bt:~# netstat -la| grep ssh
tcp        0      0 *:ssh                   *:*                     LISTEN
tcp6       0      0 [::]:ssh                [::]:*                  LISTEN

To fix X forwarding, you need to force SSH to only try to listen on the IPv4 address like so:

1. To /etc/ssh/sshd_config, add this line:

AddressFamily inet

2. Restart SSH.
3. For good measure, you might want to delete your ~/.Xauthority file just to start from scratch.

That’s it. Next time you connect, a new Xauthority file will be generated, the DISPLAY variable will be properly set, and X applications will run as expected.

References

openssh-server: Fails to bind port for X11 forwarding, ipv4/ipv6 mess

Leave a Reply

Your email address will not be published. Required fields are marked *