Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm running an Ubuntu Server 12.04, and recently I configured it to do NAT for my laptop. Since the server has only one NIC, I followed instructions online to create a virtual network device (eth0:0) that has a LAN IP address, then further configured iptables and UFW to allow internet sharing. However, just a few days ago, I discovered that one of the PHP pages hosted on the server failed for no apparent reason. A little digging revealed that the MySQL server started refusing connections from localhost. The same happened with a page (PhpMyAdmin) that was configured to be accessible only from localhost (in Apache2).

The error, as shown by $mysql --protocol=tcp -u root -p looks like

ERROR 1130 (HY000): Host '<host name of eth0>' is not allowed to connect to this MySQL server

However, the funny thing is, I configured the mysql server to allow root access from localhost (only). Moreover, the mysql server listens only on, as shown by:

sudo netstat -npa | head
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0*               LISTEN      1029/mysqld

which means that the connection could have only come from (Note that MySQL is working because I can still connect to it via unix domain sockets)

In effect, it seems that all tcp connections originating from to appear to any local daemon to come from the eth0 IP address. Indeed, apache2 allowed me to access PhpMyAdmin after I added allow <eth0 IP address>.

The following are my network configurations (redacted):

/etc/hosts:       localhost
211.x.x.x   <host name of eth0>      <server name>
#IPv6 Defaults follows ....


auto lo
iface lo inet loopback

auto eth0
iface eth0 inet static
address 211.x.x.x
gateway 211.x.x.x
# dns-* options are implemented by the resolvconf package, if installed
hwaddress ether xx:xx:xx:xx:xx:xx

auto eth0:0
iface eth0:0 inet static


#Uncommented the following lines



/etc/init/internet-sharing.conf (upstart script I wrote), section pre-start script:

iptables -A FORWARD -o eth0 -i eth0:0 -s -m conntrack --ctstate NEW -j ACCEPT
iptables -A FORWARD -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
iptables -A POSTROUTING -t nat -j MASQUERADE

Note again that my problem here is that programs cannot access localhost tcp services, from the server itself, and that access is blocked because the services have access control allowing only I have no problem connecting (as in TCP connections) to services via tcp, even if the services listen only on I do NOT want to connect to the services from another computer.

share|improve this question

It appears that the problem is the third iptables NAT rule. Since I didn't specify and filtering rule for the final POSTROUTING nat rule, it somehow matched localhost packets, and translated their source IP addresses to the eth0 address. A fixed startup script is shown below:

iptables -A FORWARD -o eth0 -i eth0:0 -s -m conntrack --ctstate NEW -j ACCEPT
iptables -A FORWARD -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
iptables -A POSTROUTING -s -t nat -j MASQUERADE

Note the additional -s option.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.