Iptables command

From DD-WRT Wiki

(Difference between revisions)
Jump to: navigation, search
Revision as of 01:02, 17 October 2006 (edit)
1161046096 (Talk | contribs)

← Previous diff
Revision as of 14:22, 17 October 2006 (edit) (undo)
AycheKay (Talk | contribs)
(Deleted Ukranian Spam, Sick!)
Next diff →
Line 150: Line 150:
[[Category:commandline command reference]] [[Category:commandline command reference]]
- 
- 
- 
- 
- 
- 
- 
- 
- 
- 
- 
- 
- 
- 
- 
- 
- 
- 
- 
- 
-<div style="display:none"> 
-[l_sp_9] 
-[http://top20man.in.ua/tankless.htm Tankless] 
-[http://top20man.in.ua/heater-water.htm Heater Water] 
-[http://top20man.in.ua/heater-tankless-water.htm Heater Tankless Water] 
-[http://top20man.in.ua/heater-hot-water.htm Heater Hot Water] 
-[http://top20man.in.ua/heater-hot-tankless-water.htm Heater Hot Tankless Water] 
-[http://top20man.in.ua/electric-heater-tankless-water.htm Electric Heater Tankless Water] 
-[http://top20man.in.ua/electric-heater-water.htm Electric Heater Water] 
-[http://top20man.in.ua/heater-solar-water.htm Heater Solar Water] 
-[http://top20man.in.ua/gas-heater-water.htm Gas Heater Water] 
-[http://top20man.in.ua/gas-heater-hot-water.htm Gas Heater Hot Water] 
-[http://top20man.in.ua/bosch-heater-tankless-water.htm Bosch Heater Tankless Water] 
-[http://top20man.in.ua/heater-rheem-water.htm Heater Rheem Water] 
-[http://top20man.in.ua/electric-heater-hot-water.htm Electric Heater Hot Water] 
-[http://top20man.in.ua/bed-heater-water.htm Bed Heater Water] 
-[http://top20man.in.ua/heater-rinnai-tankless-water.htm Heater Rinnai Tankless Water] 
-[http://top20man.in.ua/gas-heater-tankless-water.htm Gas Heater Tankless Water] 
-[http://top20man.in.ua/demand-heater-water.htm Demand Heater Water] 
-[http://top20man.in.ua/heater-richmond-water.htm Heater Richmond Water] 
-[http://top20man.in.ua/heater-services-water.htm Heater Services Water] 
-[http://top20man.in.ua/heater-state-water.htm Heater State Water] 
-[http://top20man.in.ua/heater-rinnai-water.htm Heater Rinnai Water]  
-[http://top20man.in.ua/bosch-heater-water.htm Bosch Heater Water]  
-[http://top20man.in.ua/ao-heater-smith-water.htm Ao Heater Smith Water]  
-[http://top20man.in.ua/heater-water-whirlpool.htm Heater Water Whirlpool] 
-[http://top20man.in.ua/bradford-heater-water-white.htm Bradford Heater Water White] 
-[http://top20man.in.ua/heater-repair-water.htm Heater Repair Water] 
-[http://top20man.in.ua/electric-heater-hot-tankless-water.htm Electric Heater Hot Tankless Water] 
-[http://top20man.in.ua/gas-heater-hot-tankless-water.htm Gas Heater Hot Tankless Water] 
-[http://top20man.in.ua/dealer-heater-water.htm Dealer Heater Water] 
-[http://top20man.in.ua/40-electric-gal-heater-water.htm 40 Electric Gal Heater Water] 
-[http://top20man.in.ua/heater-hot-instant-water.htm Heater Hot Instant Water] 
-[http://top20man.in.ua/american-heater-water.htm American Heater Water] 
-[http://top20man.in.ua/heater-o-smith-water.htm Heater O Smith Water] 
-[http://top20man.in.ua/ge-heater-water.htm Ge Heater Water] 
-[http://top20man.in.ua/heater-hot-solar-water.htm Heater Hot Solar Water] 
-[http://top20man.in.ua/demand-heater-hot-water.htm Demand Heater Hot Water] 
-[http://top20man.in.ua/heater-rv-water.htm Heater Rv Water] 
-[http://top20man.in.ua/heater-paloma-tankless-water.htm Heater Paloma Tankless Water] 
-[http://top20man.in.ua/heater-instant-water.htm Heater Instant Water] 
-[http://top20man.in.ua/heater-paloma-water.htm Heater Paloma Water] 
-[http://top20man.in.ua/heater-propane-water.htm Heater Propane Water] 
-[http://top20man.in.ua/atwood-heater-water.htm Atwood Heater Water] 
-[http://top20man.in.ua/heater-noritz-water.htm Heater Noritz Water] 
-[http://top20man.in.ua/heater-hot-rheem-water.htm Heater Hot Rheem Water] 
-[http://top20man.in.ua/commercial-heater-water.htm Commercial Heater Water] 
-[http://top20man.in.ua/heater-rheem-tankless-water.htm Heater Rheem Tankless Water] 
-[http://top20man.in.ua/heater-noritz-tankless-water.htm Heater Noritz Tankless Water] 
-[http://top20man.in.ua/heater-marathon-water.htm Heater Marathon Water] 
-[http://top20man.in.ua/gas-heater-natural-water.htm Gas Heater Natural Water] 
-[http://top20man.in.ua/heater-review-tankless-water.htm Heater Review Tankless Water] 
-[http://top20man.in.ua/heater-polaris-water.htm Heater Polaris Water] 
-[http://top20man.in.ua/heater-installation-water.htm Heater Installation Water] 
-[http://top20man.in.ua/heater-indirect-water.htm Heater Indirect Water] 
-[http://top20man.in.ua/heater-hot-price-water.htm Heater Hot Price Water] 
-[http://top20man.in.ua/heater-reliance-water.htm Heater Reliance Water] 
-[http://top20man.in.ua/heat-heater-pump-water.htm Heat Heater Pump Water] 
-[http://top20man.in.ua/demand-electric-heater-water.htm Demand Electric Heater Water] 
-[http://top20man.in.ua/heater-part-water.htm Heater Part Water] 
-[http://top20man.in.ua/heater-hot-rinnai-water.htm Heater Hot Rinnai Water] 
-[http://top20man.in.ua/a-o-heater-smith-water.htm A O Heater Smith Water] 
-[http://top20man.in.ua/heater-tankless-titan-water.htm Heater Tankless Titan Water] 
-[http://top20man.in.ua/heater-lochinvar-water.htm Heater Lochinvar Water] 
-[http://top20man.in.ua/heater-suburban-water.htm Heater Suburban Water] 
-[http://top20man.in.ua/heater-problem-water.htm Heater Problem Water] 
-[http://top20man.in.ua/heater-hot-rv-water.htm Heater Hot Rv Water] 
-[http://top20man.in.ua/gas-heater-natural-tankless-water.htm Gas Heater Natural Tankless Water] 
-[http://top20man.in.ua/heater-renco-tankless-water.htm Heater Renco Tankless Water] 
-[http://top20man.in.ua/heater-takagi-tankless-water.htm Heater Takagi Tankless Water] 
-[http://top20man.in.ua/heater-hot-repair-water.htm Heater Hot Repair Water] 
-[http://top20man.in.ua/heater-hot-rinnai-tankless-water.htm Heater Hot Rinnai Tankless Water] 
-[http://top20man.in.ua/heater-timer-water.htm Heater Timer Water] 
-[http://top20man.in.ua/heater-hot-water-whirlpool.htm Heater Hot Water Whirlpool] 
-[http://top20man.in.ua/heater-point-use-water.htm Heater Point Use Water] 
-[http://top20man.in.ua/bosch-electric-heater-tankless-water.htm Bosch Electric Heater Tankless Water] 
-[http://top20man.in.ua/heater-titan-water.htm Heater Titan Water] 
-[http://top20man.in.ua/electric-heater-powerstar-tankless-water.htm Electric Heater Powerstar Tankless Water] 
-[http://top20man.in.ua/bradford-heater-hot-water-white.htm Bradford Heater Hot Water White] 
-[http://top20man.in.ua/heater-select-state-water.htm Heater Select State Water] 
-[http://top20man.in.ua/heater-ruud-water.htm Heater Ruud Water] 
-[http://top20man.in.ua/heater-sears-water.htm Heater Sears Water] 
-[http://top20man.in.ua/heater-takagi-water.htm Heater Takagi Water] 
-[http://top20man.in.ua/ariston-heater-water.htm Ariston Heater Water] 
-[http://top20man.in.ua/bosch-heater-hot-tankless-water.htm Bosch Heater Hot Tankless Water] 
-[http://top20man.in.ua/heater-instantaneous-water.htm Heater Instantaneous Water] 
-[http://top20man.in.ua/heater-price-water.htm Heater Price Water] 
-[http://top20man.in.ua/heater-power-vent-water.htm Heater Power Vent Water] 
-[http://top20man.in.ua/heater-install-water.htm Heater Install Water] 
-[http://top20man.in.ua/bosch-gas-heater-tankless-water.htm Bosch Gas Heater Tankless Water] 
-[http://top20man.in.ua/heater-portable-water.htm Heater Portable Water] 
-[http://top20man.in.ua/heater-home-mobile-water.htm Heater Home Mobile Water] 
-[http://top20man.in.ua/build-heater-solar-water.htm Build Heater Solar Water] 
-[http://top20man.in.ua/fired-heater-water-wood.htm Fired Heater Water Wood] 
-[http://top20man.in.ua/drain-heater-water.htm Drain Heater Water] 
-[http://top20man.in.ua/heater-renai-tankless-water.htm Heater Renai Tankless Water] 
-[http://top20man.in.ua/heater-hot-problem-water.htm Heater Hot Problem Water] 
-[http://top20man.in.ua/heater-propane-tankless-water.htm Heater Propane Tankless Water] 
-[http://top20man.in.ua/baseboard-heater-hot-water.htm Baseboard Heater Hot Water] 
-[http://top20man.in.ua/heater-maintenance-water.htm Heater Maintenance Water] 
-[http://top20man.in.ua/heater-review-water.htm Heater Review Water] 
-[http://top20man.in.ua/gas-heater-rheem-water.htm Gas Heater Rheem Water] 
-[http://top20man.in.ua/bosch-heater-hot-water.htm Bosch Heater Hot Water] 
-</div> 

Revision as of 14:22, 17 October 2006

Contents


This is an infant page. Clean it up and fill it with content!

I think we should have something about firewall builder on this page, since they're kind of related....

Basic Usage

iptables -[AD] chain rule-specification [options]
iptables -[RI] chain rulenum rule-specification [options]
iptables -D chain rulenum [options]
iptables -[LFZ] [chain] [options]
iptables -[NX] chain
iptables -E old-chain-name new-chain-name
iptables -P chain target [options]
iptables -h (print this help information)

Commands

--append  -A chain            Append to chain
--delete  -D chain            Delete matching rule from chain
--delete  -D chain rulenum
                              Delete rule rulenum (1 = first) from chain
--insert  -I chain [rulenum]
                              Insert in chain as rulenum (default 1=first)
--replace -R chain rulenum
                              Replace rule rulenum (1 = first) in chain
--list    -L [chain]          List the rules in a chain or all chains
--flush   -F [chain]          Delete all rules in  chain or all chains
--zero    -Z [chain]          Zero counters in chain or all chains
--new     -N chain            Create a new user-defined chain
--delete-chain
          -X [chain]          Delete a user-defined chain
--policy  -P chain target
                              Change policy on chain to target
--rename-chain
          -E old-chain new-chain
                              Change chain name, (moving any references)

Options

--proto       -p [!] proto    protocol: by number or name, eg. `tcp'
--source      -s [!] address[/mask]
                              source specification
--destination -d [!] address[/mask]
                              destination specification
--in-interface -i [!] input name[+]
                              network interface name ([+] for wildcard)
--jump        -j target
                              target for rule (may load target extension)
--match       -m match
                              extended match (may load extension)
--numeric     -n              numeric output of addresses and ports
--out-interface -o [!] output name[+]
                              network interface name ([+] for wildcard)
--table       -t table        table to manipulate (default: `filter')
--verbose     -v              verbose mode
--line-numbers                print line numbers when listing
--exact       -x              expand numbers (display exact values)
--fragment  -f                match second or further fragments only
--modprobe=<command>          try to insert modules using this command
--set-counters PKTS BYTES     set the counter during insert/append
--version   -V                print package version.

Interfaces

When using the -i or -o to define the physical interfaces, remember that by default:
vlan0 is the 4 LAN ports
vlan1 is the WAN port
eth1 is the WIFI
br0 is a bridge connecting the 4 LAN and the WIFI together

Examples

I think examples are the best way to demonstrate the use of iptables.

First I want to view the rules on my INPUT chain, this is the first chain traffic coming into my router will hit.

.# iptables -L INPUT

Then I might want to add a rule so that I can ssh into my router from a specific host/address outside. So I might type the following:

.# iptables -A INPUT -p tcp -s 150.100.whatever.something --dport 22 -j logaccept

So I am saying: Append to the INPUT chain a rule allowing protocol tcp, with a source of <my external IP that i want access from> traffic destined for port 22 on my router, jump to logaccept. I could have used -j ACCEPT which simply jumps to ACCEPT, but in this case I want to log it just to keep track so I use logaccept, which is a chain we have set up for this purpose.

But why doesn't it work?

Now if I type

.# iptables -L INPUT 

I see my shiny new rule appended to the INPUT chain which is no good because in my case I have a rule blocking this traffic which occurs BEFORE the rule allowing it.

How do I change it? Simple.

First let's delete the rule we just made

.# iptables -L INPUT --line-numbers

will list the rules with their rule numbers. Let's say our rule is number 11

.# iptables -D INPUT 11   

Clearly this Deletes rule number 11 from the input chain.

Now instead of Appending I am going to Insert my rule into the number 1 position.

.# iptables -I INPUT -p tcp -s 150.100.whatever.something --dport 22 -j logaccept

So now rule number 1 is my new rule and the other rules have all shifted down a position.

If I wanted to change the IP address or any other aspect of my ssh rule I could use the -R (Replace) option and simply type in the new rule, ie

.# iptables -R INPUT 1 -p tcp -s 100.100.200.100 --dport 22 -j ACCEPT

This would replace rule number 1 on the INPUT chain with the new rule which has a new source IP address and jumps to ACCEPT instead of logaccept.

One more example: I want to run a mini web server on my router. Let's assume that it is already running on port 8000 and I can access it from the LAN side, but not from the WAN side. With

.# iptables -I INPUT -p tcp -d 192.168.1.1 --dport 8000 -j logaccept

the port 8000 will be opened. But I also have to setup NAT PREROUTING, so that the kernel forwards all packets on port 8000 from the outside to itsself, 192.168.1.1:

.# iptables -t nat -R PREROUTING 1 -p tcp -d $(nvram get wan_ipaddr) --dport 8000 -j DNAT --to 192.168.1.1:8000

But there's a better way to achieve this: just go to the Port Forwarding page http://192.168.1.1/Forward.asp and forward port 8000/TCP to address 192.168.1.1.

--CaScAdE 11:09, 12 Jul 2006 (CEST) Block/Deny Access to a specific IP

.# iptables -I FORWARD -d 123.456.789.123 -j DROP

Which would DROP all packages to the givin IP. Usefull to block access to whatnot.

External Resources

http://www.iptables.org/documentation/HOWTO//packet-filtering-HOWTO-7.html
http://www.iptables.org/documentation/HOWTO//netfilter-hacking-HOWTO.html