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

I'm replacing a wireless router running Tomato with an ubuntu server with dual NICs. I ssh'd into the tomato router and found /etc/iptables there and all the rules make sense based on what I'm reading. I'll probably use webmin once the server is set up and running. (as I'm writing this question, I'm already copying qos and dnsmasq settings files)

Is setting up iptables really as easy as changing the interfaces' names and saving the same file onto the Debian server?

Tomato: vlan1 (public), br0 (private wired), and eth1 (private wireless)
Ubuntu: eth0 (public) and eth1 (private).

The tomato config file with interfaces' names changed:

:QOSO - [0:0]
-A QOSO -j CONNMARK --restore-mark --mask 0xff
-A QOSO -m connmark ! --mark 0/0xff00 -j RETURN
-A QOSO -p tcp -m mport --dports 80,443   -m bcount --range 0x0-0x7ffff -j CONNMARK --set-return 0x2/0xFF
-A QOSO -p tcp -m mport --dports 80,443   -m bcount --range 0x80000 -j CONNMARK --set-return 0x4/0xFF
-A QOSO -p udp --dport 53   -m bcount --range 0x0-0x7ff -j CONNMARK --set-return 0x1/0xFF
-A QOSO -p tcp --dport 53   -m bcount --range 0x0-0x7ff -j CONNMARK --set-return 0x1/0xFF
-A QOSO -p udp --dport 53   -m bcount --range 0x800 -j CONNMARK --set-return 0x5/0xFF
-A QOSO -p tcp --dport 53   -m bcount --range 0x800 -j CONNMARK --set-return 0x5/0xFF
-A QOSO -p udp --dport 1024:65535   -j CONNMARK --set-return 0x5/0xFF
-A QOSO -p tcp --dport 1024:65535   -j CONNMARK --set-return 0x5/0xFF
-A QOSO -p udp -m mport --ports 5060:5090  -m layer7 --l7dir /etc/l7-protocols --l7proto sip -j CONNMARK --set-return 0x101/0xFF
-A QOSO -j CONNMARK --set-return 0x4
-A FORWARD -o eth0 -j QOSO
-A OUTPUT -o eth0 -j QOSO
-A PREROUTING -i eth0 -d -j DROP
-A PREROUTING -p icmp -d -j DNAT --to-destination
-A PREROUTING  -p tcp -m tcp -d --dport 22 -j DNAT --to-destination
-A PREROUTING -p tcp  -d --dport 8822 -j DNAT --to-destination
-A POSTROUTING -p tcp --dport 22 -s -d -j SNAT --to-source
:upnp - [0:0]
-A PREROUTING -d -j upnp
-A INPUT -i eth1 -d -j DROP
-A INPUT -m state --state INVALID -j DROP
-N shlimit
-A shlimit -m recent --set --name shlimit
-A shlimit -m recent --update --hitcount 3 --seconds 60 --name shlimit -j DROP
-A INPUT -p tcp --dport 22 -m state --state NEW -j shlimit
-A INPUT -i eth1 -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -p tcp  -m tcp -d --dport 22 -j ACCEPT
-A FORWARD -i eth1 -o eth1 -j ACCEPT
-A FORWARD -m state --state INVALID -j DROP
-A FORWARD -p tcp --tcp-flags SYN,RST SYN -m tcpmss --mss 1461: -j TCPMSS --set-mss 1460
:L7in - [0:0]
-A FORWARD -i eth0 -j L7in
-A L7in -m layer7 --l7dir /etc/l7-protocols --l7proto sip -j RETURN
:wanin - [0:0]
:wanout - [0:0]
-A FORWARD -i eth0 -j wanin
-A FORWARD -o eth0 -j wanout
-A FORWARD -i eth1 -j ACCEPT
:upnp - [0:0]
-A FORWARD -i eth0 -j upnp
-A wanin  -p tcp -m tcp -d --dport 22 -j ACCEPT

Edited to add: I've also been reading from these two great resources:

Edited to add:
1. Ended up changing to Debian. Ubuntu 12.04 LTS was requiring too many hacks to get working on my hardware.
2. iptables does not recognize the mport module, but that's a different question.

share|improve this question
up vote 3 down vote accepted

Yep... it's just as simple as copy/paste & adjust interface names as appropriate. Iptables on tomato, is the same as iptables on ubuntu/debian/centos/red hat/suse/dsl/openwrt/ddwrt/puppy/etc... The only potential conflict between flavors of OSes... is whether or not specific iptables modules were compiled/installed.

The configuration you posted above is generated by iptables-save and should be read by iptables-restore. It is NOT read by default on most linux-flavors... so you may need to create an init script to restore the settings on boot.

On Ubuntu, you can simply edit /etc/rc.local and add this:

sudo iptables-restore < /etc/iptables

The only non-standard installed module you're using that I see is the "layer7" module... but its easy to install in ubuntu. Just do an

sudo apt-get install l7-filter-userspace l7-protocols

and you're done.

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.