Skip to contentSkip to conversation

sub interface filtering

DISCUSSION Mike 4 participants 6 messages Apr 2, 2003 – Apr 3, 2003

lore
Share & tools
lore

Mike

author
#0 lore raw

Hi guys I have the following setup and rules. And I cant seem to get the filtering to work.

Interfaces:

eth0

<internetIP>

eth1

<privateIP>

eth2

<routeable internetIP/28>

eth2:0

<routeable internetIP/28>

eth2:1

<routeable internetIP/28>

I have the following rules

iptables -P FORWARD DROP

iptables -I FORWARD -i eth0 -o eth2 -p tcp -m state --state NEW,ESTABLISHED,RELATED --dport 80 -j ACCEPT

iptables -I FORWARD -i eth0 -o eth2 -p tcp -m state --state NEW,ESTABLISHED,RELATED --dport 443 -j ACCEPT

iptables -A FORWARD -i eth0 -o eth2 -p tcp -m state --state NEW,ESTABLISHED,RELATED,INVALID -j DROP

iptables -t nat -A PREROUTING -p tcp <routeable internetIP/28> --dport 80 -j DNAT --to 192.168.1.197

iptables -t nat -A PREROUTING -p tcp <routeable internetIP/28> --dport 443 -j DNAT --to 192.168.1.197
iptables -t nat -A POSTROUTING -o eth2 -s 192.168.1.197 -j SNAT --to <routeable internetIP/28

ifconfig eth2:0 <routeable internetIP/28> broadcast <routeable internetIP/28> netmask 255.255.255.240

iptables -t nat -A PREROUTING -p tcp -d <routeable internetIP/28 --dport 80 -j DNAT --to 192.168.1.198

iptables -t nat -A PREROUTING -p tcp <routeable internetIP/28> --dport 443 -j DNAT --to 192.168.1.198
iptables -t nat -A POSTROUTING -o eth2 -s 192.168.1.198 -j SNAT --to <routeable internetIP/28

ifconfig eth2:1 <routeable internetIP/28> broadcast <routeable internetIP/28> netmask 255.255.255.240

but when I scan eth2:1 or eth2:2 from an outside machine I can see ALL the local services (ssh, ptptp,dns etc..) Is connection not passing the forwading chain?

#1 lore raw
Quoted 6 lines · Mike

but when I scan eth2:1 or eth2:2 from an outside machine I can see ALL the local services (ssh, ptptp,dns etc..) Is connection not passing the forwading chain?

You obviously have the INPUT chain set to a policy of ACCEPT. All locally destined packets go through the INPUT chain, all forwarded packets go through the FORWARD chain. Add apropriate rules for the INPUT chain.

HTH,
Martijn Lievaart

#2 lore raw
In reply to Mike
Quoted 1 line

Hi guys I have the following setup and rules. And I cant seem to get

the filtering to work.

Quoted 7 lines

eth2:0

<routeable internetIP/28>

eth2:1

<routeable internetIP/28>

AFAIK it is because you cannot filter eth<x>:y (but you can filter the IP address of course).

Rob

#3 lore raw
In reply to Mike
Quoted 6 lines · Mike

Hi guys I have the following setup and rules. And I cant seem to get the filtering to work.

iptables -t nat -A PREROUTING -p tcp <routeable internetIP/28> --dport 80 -j DNAT --to 192.168.1.197

Quoted 8 lines

iptables -t nat -A PREROUTING -p tcp <routeable internetIP/28> --dport 443 -j DNAT --to 192.168.1.197
iptables -t nat -A POSTROUTING -o eth2 -s 192.168.1.197 -j SNAT --to <routeable internetIP/28

but when I scan eth2:1 or eth2:2 from an outside machine I can see ALL the local services (ssh, ptptp,dns etc..) Is connection not passing the forwading chain?

You are DNATting dport 80 and dport 443, but the remainder of the ports are not being DNATted, so they still target the firewall box. You'd need to DNAT all connections to the specified IP, then DROP all except ports 80 and 443 in FORWARD to avoid this.

Of course, this also shows that you are letting lots of (all?!?) ports through the INPUT chain to the box itself from outside, which you should lock down as well... A DROP policy on INPUT is called for, then ACCEPT required ports from eth2 for externally-accessed services (if any) and ACCEPT required (or all if desired) ports from the LAN machines.

j

author
#4 lore raw

Joel,
I tried forwarding ALL connections and then filtering by the
forward chain but no luck. Once it reaches the PREROUTING chain and makes its descision does it pass anymore chains? Or is that it. I have always read you don't want to filter in the NAT table and PREROUTING doesn't have a filter table just a NAT & MANGLE. Any ideas?

-Mike
----- Original Message -----
From: "Joel Newkirk" <[email protected]>
To: "Mike" <[email protected]>; <[email protected]>
Sent: Wednesday, April 02, 2003 3:56 PM
Subject: Re: sub interface filtering

Quoted 6 lines · Mike

Hi guys I have the following setup and rules. And I cant seem to get the filtering to work.

iptables -t nat -A PREROUTING -p tcp <routeable internetIP/28> --dport 80 -j DNAT --to 192.168.1.197

Quoted 8 lines

iptables -t nat -A PREROUTING -p tcp <routeable internetIP/28> --dport 443 -j DNAT --to 192.168.1.197
iptables -t nat -A POSTROUTING -o eth2 -s 192.168.1.197 -j SNAT --to <routeable internetIP/28

but when I scan eth2:1 or eth2:2 from an outside machine I can see ALL the local services (ssh, ptptp,dns etc..) Is connection not passing the forwading chain?

You are DNATting dport 80 and dport 443, but the remainder of the ports are not being DNATted, so they still target the firewall box. You'd need to DNAT all connections to the specified IP, then DROP all except ports 80 and 443 in FORWARD to avoid this.

Of course, this also shows that you are letting lots of (all?!?) ports through the INPUT chain to the box itself from outside, which you should lock down as well... A DROP policy on INPUT is called for, then ACCEPT required ports from eth2 for externally-accessed services (if any) and ACCEPT required (or all if desired) ports from the LAN machines.

j

#5 lore raw
Quoted 4 lines · Mike

Joel,
I tried forwarding ALL connections and then filtering by the
forward chain but no luck. Once it reaches the PREROUTING chain and makes its descision does it pass anymore chains? Or is that it. I have

It still passes the filter table chains, either INPUT or FORWARD.

Quoted 1 line

always read you don't want to filter in the NAT table and PREROUTING

That's right. In some circumstances traffic will bypass those chains. (IE, you have an established connection that is being NATted, it's traffic will usually not appear in NAT PREROUTING, just the first packet) Normally you should only have ACCEPT, DNAT, or REDIRECT targets in that chain, and an ACCEPT policy. (The MIRROR target would be valid there as well, and any traffic MIRRORed would NOT appear in any subsequent chains... MIRROR should only be used if you really understand what it is doing, really need it, and are really careful with it)

Quoted 1 line

doesn't have a filter table just a NAT & MANGLE. Any ideas?

Two. One is to try:
iptables -I FORWARD 1 -j LOG --log-prefix "FWDLOGALL:"
which will log every packet passing through FORWARD chain, with "FWDLOGALL" prepended to each entry. This will let you see precisely what traffic is going through, and what it looks like (re IPs, ports, etc). It can also potentially generate a huge number of log entries, so don't leave it in any longer than necessary! You can of course do the same thing with "-t nat -I PREROUTING 1" to see ALL traffic that is presenting to the box, and narrow down either LOG rule by matching IPs, ports, interface, etc. (although "-i" will only match the physical interface)

I've just tested here and it works. (actually I already knew it would, but wanted to generate the log entries :^) I set PREROUTING rules on my gateway to LOG then DNAT all connections inbound on ppp0 to my desktop machine, and LOG all traffic in FORWARD, then ssh'd back to myself from a remote SSH session I had open. The ssh connection was DNATted properly and it was LOGged in FORWARD. Then it was subsequently DROPped since I only accept SSH connections in FORWARD that originate on my desktop machine, and always LOG any DROPs in FORWARD.

Apr  3 11:43:32 janus kernel: DNATTEST:IN=ppp0 OUT= MAC= SRC= {elided} 

DST=141.150.211.149 LEN=60 TOS=0x00 PREC=0x00 TTL=53 ID=62380 DF PROTO=TCP SPT=35792 DPT=22 WINDOW=5840 RES=0x00 SYN URGP=0

Apr  3 11:43:32 janus kernel: FWDLOG:IN=ppp0 OUT=eth1 SRC= {elided} 

DST=192.168.0.1 LEN=60 TOS=0x00 PREC=0x00 TTL=52 ID=62380 DF PROTO=TCP SPT=35792 DPT=22 WINDOW=5840 RES=0x00 SYN URGP=0

Apr  3 11:43:32 janus kernel: IPT:FORWARDdrop:IN=ppp0 OUT=eth1 SRC= 

{elided} DST=192.168.0.1 LEN=60 TOS=0x00 PREC=0x00 TTL=52 ID=62380 DF PROTO=TCP SPT=35792 DPT=22 WINDOW=5840 RES=0x00 SYN URGP=0

The other approach is to just DNAT the ports you need, and make sure you DROP everything on INPUT. Since your scenario here is multiple IPs on a single interface, each forwarding to a different local machine, the first approach makes more sense - if you need to open/close ports to a given local machine later then everything is already set up, you just filter in the FORWARD chain as usual.

j

Quoted 36 lines

-Mike
----- Original Message -----
From: "Joel Newkirk" <[email protected]>
To: "Mike" <[email protected]>; <[email protected]>
Sent: Wednesday, April 02, 2003 3:56 PM
Subject: Re: sub interface filtering

Quoted 6 lines · Mike

Hi guys I have the following setup and rules. And I cant seem to get the filtering to work.

iptables -t nat -A PREROUTING -p tcp <routeable internetIP/28> --dport 80 -j DNAT --to 192.168.1.197

Quoted 8 lines

iptables -t nat -A PREROUTING -p tcp <routeable internetIP/28> --dport 443 -j DNAT --to 192.168.1.197
iptables -t nat -A POSTROUTING -o eth2 -s 192.168.1.197 -j SNAT --to <routeable internetIP/28

but when I scan eth2:1 or eth2:2 from an outside machine I can see ALL the local services (ssh, ptptp,dns etc..) Is connection not passing the forwading chain?

You are DNATting dport 80 and dport 443, but the remainder of the ports are not being DNATted, so they still target the firewall box. You'd need to DNAT all connections to the specified IP, then DROP all except ports 80 and 443 in FORWARD to avoid this.

Of course, this also shows that you are letting lots of (all?!?) ports through the INPUT chain to the box itself from outside, which you should lock down as well... A DROP policy on INPUT is called for, then ACCEPT required ports from eth2 for externally-accessed services (if any) and ACCEPT required (or all if desired) ports from the LAN machines.

j