Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

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

The following are my iptable rules on a ubuntu cloud server:

cat /etc/iptables.rules:

:INPUT DROP [598:41912]  
:OUTPUT ACCEPT [456:35354] 
-A INPUT -i lo -j ACCEPT  
-A INPUT -p tcp -m tcp --dport 80 -j ACCEPT  
-A INPUT -m state -i eth0 --state ESTABLISHED,RELATED -j ACCEPT  
-A INPUT -s -p tcp -m tcp --dport 22 -j ACCEPT  
-A INPUT -s -p tcp -m tcp --dport 3306 -j ACCEPT
-A INPUT -s -p tcp -m tcp --dport 10000 -j ACCEPT

I did not open the ftp port 21 in the above iptable rules but I'm allowed to connect to the server via ftp. How?

nmap server-ip

Not shown: 987 closed ports 

21/tcp        open     ftp
22/tcp        open     ssh
25/tcp        open     smtp
53/tcp        open     domain
80/tcp        open     http
111/tcp       open     rpcbind
135/tcp       filtered msrpc
139/tcp       filtered netbios-ssn
389/tcp       open     ldap
445/tcp       filtered microsoft-ds
10000/tcp      open     java-or-OTGfileshare
2401/tcp      open     cvspserver
3306/tcp      open     mysql

Nmap done: 1 IP address (1 host up) scanned in 17.46 seconds

why these many ports are shown as open. I'm clear that these services are running on the server but how it could list or connect(ftp) these ports when it is not included in the iptable rules?.

need help...

The following script will be running at every 5 mins on cloud servers to update their iptables for the dyndns domain name:

# A script to update iptable records for dynamic dns hosts.
# Written by: Dave Horner (
# Released into public domain.
# Run this script in your cron table to update ips.
# You might want to put all your dynamic hosts in a sep. chain.
# That way you can easily see what dynamic hosts are trusted.
# create the chain in iptables.
 /sbin/iptables -N dynamichosts
# insert the chain into the input chain @ the head of the list.
 /sbin/iptables -I INPUT 1 -j dynamichosts
# flush all the rules in the chain
 /sbin/iptables -F dynamichosts

CHAIN="dynamichosts"  # change this to whatever chain you want.

# check to make sure we have enough args passed.
if [ "${#@}" -ne "1" ]; then
    echo "$0 hostname"
    echo "You must supply a hostname to update in iptables."

# lookup host name from dns tables
IP=`/usr/bin/dig +short $HOST | /usr/bin/tail -n 1`
if [ "${#IP}" = "0" ]; then
    echo "Couldn't lookup hostname for $HOST, failed."

if [ -a $HOSTFILE ]; then
    # echo "CAT returned: $?"

# save off new ip.

echo "Updating $HOST in iptables."
if [ "${#OLDIP}" != "0" ]; then
    echo "Removing old rule ($OLDIP)"
echo "Inserting new rule ($IP)"

This is the output of "ipables -L" on the cloud server.

dynamichosts  all  --  anywhere             anywhere            
dynamichosts  all  --  anywhere             anywhere            
dynamichosts  all  --  anywhere             anywhere            
dynamichosts  all  --  anywhere             anywhere            
dynamichosts  all  --  anywhere             anywhere            
ACCEPT     all  --  anywhere             anywhere
ACCEPT     tcp  --  anywhere             anywhere tcp dpt:www
ACCEPT     all  --  anywhere             anywhere state RELATED,ESTABLISHED 
ACCEPT     all  --  anywhere             anywhere state RELATED,ESTABLISHED 
ACCEPT     tcp  --  anywhere tcp dpt:ssh 
ACCEPT     tcp  -- anywhere tcp dpt:10000 
ACCEPT     tcp  --  anywhere tcp dpt:mysql 
DROP       all  --  anywhere             anywhere

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         

Chain dynamichosts (937 references)
target     prot opt source               destination         
ACCEPT     all  --  anywhere

Here the airtelbroadband is mine(dyndns domainname). I think the previously posted script creates new chain and from this domain everything is allowed -is it so?. May be the allowed ports ssh, webmin, mysql and www are useless entries. But I want this domain should be allowed only to these ports and I may have nmap listing only allowed ports on the cloud server when I check from my dyndns domain systems. Any more help...?

share|improve this question
I assume you are running nmap from outside your server, right ? Execute the following command: "iptables -vLn". That should really tell you if anyone added a rule that matches the open ports you are seeing. Add the output from that command to the question for completeness. – Torian Oct 7 '10 at 13:25

Scan to a remote host. "-A INPUT -i lo -j ACCEPT" allow traffic from server-ip to server-ip.

share|improve this answer
Would it be any problem if dont include "-A INPUT -i lo -j ACCEPT" as a rule?. – user53864 Oct 7 '10 at 14:05
Yes, many internal services communicate on the loopback address. – BillThor Oct 7 '10 at 16:05
Some services are not running if I remove loopback entry. – user53864 Oct 11 '10 at 12:31

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.