using iptables to route between public networks
Subject: Re: using iptables to route between public networks
From: Chris Brenton <[email protected]>
To: Matthew Simpson <[email protected]>
Cc: [email protected]
Date: Tue, 23 Dec 2003 05:53:41 -0500
Quoted 2 lines · Matthew Simpson
I have two ethernet cards in this box. One card has a public IP going to
my
Quoted 3 lines
internet provider [255.255.255.252 subnet]. The other card also has a public IP that is routed to me by my Internet provider [255.255.255.240 subnet].
<snip>
Quoted 1 line
Quoted 1 line
My first question, however... if I do a traceroute to a box connected
behind
Quoted 2 lines
Quoted 2 lines
the router, the "router" interface IP address does not show up in the traceroute. It skips directly from my internet provider's gateway
address
Quoted 5 lines
Quoted 1 line
to the final destination address. Why?
If everything is configured correctly it should, although most people would consider this a "feature" as they deny inbound trace attempts.
Quoted 8 lines
If it does actually skip from your provider to the internal address, there are a couple of possibilities:
1) The Linux box is in bridging mode
2) Your subnet address space overlapsIf in between your provider's IP and the internal system is a line that shows three *'s or three characters preceded by a exclamation point, the Linux box is filtering this traffic.
There are no *'s.
To be more specific about my configuration [I'm going to munge the IP Addresses a little here since they are public, but the subnets, etc will be correct],
I have the ethernet cable from my bandwidth provider with ip address 216.190.34.38 [my side] and 216.190.34.37 [bandwidth provider's side -- gateway] with subnet 255.255.255.252 plugged into eth1.
My provider is routing 209.210.10.0/24 to me. I have eth0 set up with 209.210.10.1 subnet 255.255.255.240 [I'm not using the whole class C as of now].
I have done no config except for I have the FORWARD chain set to accept packets. I have 209.210.10.1 as the gateway on the machines behind the router.
Quoted 5 lines
Possibilities:
1) An OUTBOUND iptables filter rule
2) A sysctl setting has been changedQuoted 1 line
Second question, it's not a good idea to blindly forward all packets is
it?
Quoted 2 lines
Absolutely not. The whole purpose of a firewall is to let through only what you understand and expect to receive.
I'm not really trying to firewall, I'm just trying to route. :-) I just
want to make sure I'm not enabling someone to use my router box as a jump point to attack someone else. I know that was a problem back in the day if one set up masquerade incorrectly.
Quoted 5 lines
Quoted 3 lines
I tried to set up an append rule to the FORWARD chain to drop all packets that did not have a destination of $myiprange/28, but iptables seems to ignore the rule
Can we see the exact syntax of the rule that you entered?
I must have been doing something stupid last night, because I retried it this morning and it works. Here is what I have for the forward chain:
$IPTABLES -A FORWARD -d 209.210.10.1/28 -j ACCEPT
$IPTABLES -A FORWARD -d ! 209.210.10.1/28 -j DROP
$IPTABLES -P FORWARD ACCEPT
$IPTABLES -F FORWARD
This works.
Quoted 10 lines
Quoted 2 lines
[it doesn't work and it doesn't show up in an iptables -L] Unless forwarding all packets is okay, what should I do to fix this?
You probably already know this, so maybe its just a language thing, but there is a whole lot more you want to block besides packets not headed to you internal IP address space. Think about what services you actually have a need for letting people access from the Internet (mail server, Web server, etc.) and block access to everything else. There is a whole lot more you can do, but this will get you started in the right direction.
In this case, I need all the machines to be open. I'm eventually going to use the router to police and account for bandwidth usage, but I will be blocking precious little. All the services running on the machines behind the router need to be publically accessable.
Quoted 2 lines
HTH,
C
thanks,
mathew
Quoted 9 lines · Matthew Simpson
I must have been doing something stupid last night, because I retried it this morning and it works. Here is what I have for the forward chain:
$IPTABLES -A FORWARD -d 209.210.10.1/28 -j ACCEPT
$IPTABLES -A FORWARD -d ! 209.210.10.1/28 -j DROP
$IPTABLES -P FORWARD ACCEPT
$IPTABLES -F FORWARDThis works.
When you say "this works", is assume that's only for minimal values of "working" :)
I can't believe that a router which will drop all packets except those addressed to 209.210.10.0/28 (note that your address designation is slightly incorrect above) will do an effective job.
You may want to route inbound packets only to these IP addresses, but what
about the replies? They are going to be going to other destination
addresses, and need routing too.....
Antony.
Signature · 5 lines
If the human brain were so simple that we could understand it,
we'd be so simple that we couldn't.
Please reply to the list;
please don't CC me.I replied to Matthew off-list on this one. Note the last two lines. "It works" because he sets a default ACCEPT policy and then flushes the previous rules.
You are right about the syntax on the first two lines, but iptables is smart enough to correct it and implements 209.210.10.0/28.
C
Quoted 24 lines · Antony Stone
Quoted 9 lines · Matthew Simpson
I must have been doing something stupid last night, because I retried it this morning and it works. Here is what I have for the forward chain:
$IPTABLES -A FORWARD -d 209.210.10.1/28 -j ACCEPT
$IPTABLES -A FORWARD -d ! 209.210.10.1/28 -j DROP
$IPTABLES -P FORWARD ACCEPT
$IPTABLES -F FORWARDThis works.
When you say "this works", is assume that's only for minimal values of "working" :)
I can't believe that a router which will drop all packets except those addressed to 209.210.10.0/28 (note that your address designation is slightly incorrect above) will do an effective job.
You may want to route inbound packets only to these IP addresses, but what
about the replies? They are going to be going to other destination
addresses, and need routing too.....Antony.