Skip to contentSkip to conversation

Ip Forwarding

DISCUSSION Jason Opperisano 2 participants 4 messages Oct 28, 2004 – Oct 30, 2004 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw
Quoted 4 lines · Joe Wright

Hi, I'm new to iptables and am trying to set up a firewall for my hosting company. We have a block of 128 public ips starting at 207.145.24.128 with a mask of 255.255.255.192. I have a redhat 9 box set up with 2 nics. My goal is to have it between the router and my network.

is your current configuration that "my network" is 207.145.24.128/26 and all hosts point to the inside interface of the router as their default gateway? and now you want to wedge a firewall between "my network" and the router?

Quoted 2 lines

It should allow connections
to port 80 for all ips behind it

  iptables -A FORWARD -i $outsideIF -o $insideIF -p tcp --syn \
    --dport 80 -j ACCEPT

(assumes you are using connection tracking)

Quoted 2 lines

and I would also like to specify certain
ports for certain ips for dns, ftp, remote desktop, etc.

mport/multiport is useful for this (i prefer mport, but most distros ship with multiport):

  iptables -A FORWARD -i $outsideIF -o $insideIF -p tcp --syn \
    -d $server001 -m multiport --dports 21,3389 -j ACCEPT
Quoted 5 lines

I've found tons of
info on using iptables with nat but not much on just blocking ports for ips passing through it. I'm also not quite sure of how to configure the second nic that connects to my internal network. Any help would be greatly appreciated.

if my description of your scenario above was correct, you have a couple of options:

(a) get an additional /30 public IP space to use between the outside of the firewall and the inside of your router

(b) subnet your existing /26 and steal a /30 out of it from the beginning or end of the range for the network between the firewall and router

(c) use an RFC 1918 network for the network between the firewall and router

the "best" solution is A, but will cost some extra $$$. C can cause problems if certain situations. B is a nice compromise, basically it would involve:

router:

	inside interface:  207.145.24.129/30
	static route:      207.145.24.128/26 via 207.145.24.130

firewall:

	outside interface:  207.145.24.130/30
	inside interface:   207.145.24.190/26
	default gateway:    207.145.24.129

default gateway of hosts on the 207.145.24.128/26 network:
207.145.24.190

or some variant of the above, depending on how much readdressing you do or do not want to do.

-j

Signature · 1 line
Jason Opperisano <[email protected]>
#2 lore raw
Quoted 5 lines · Jason Opperisano
Quoted 4 lines · Joe Wright

Hi, I'm new to iptables and am trying to set up a firewall for my hosting company. We have a block of 128 public ips starting at 207.145.24.128 with a mask of 255.255.255.192. I have a redhat 9 box set up with 2 nics. My goal is to have it between the router and my network.

If you've got 128 public IPS doesn't that mean you want a netmask of 255.255.255.128? Alternatively 255.255.255.192 is a /26, giving you 207.145.24.129 to 207.145.24.190?

http://jodies.de/ipcalc

is your friend :)

<snip>

Quoted 7 lines
Quoted 2 lines

It should allow connections
to port 80 for all ips behind it

  iptables -A FORWARD -i $outsideIF -o $insideIF -p tcp --syn \
    --dport 80 -j ACCEPT

(assumes you are using connection tracking)

I think the original poster meant connections outbound... at least I hope so, inbound port 80 connections to all hosts is probably a bad idea.

Quoted 2 lines
Quoted 2 lines

and I would also like to specify certain
ports for certain ips for dns, ftp, remote desktop, etc.

Then again - OP, any chance for some clarification?

<snip>

Quoted 11 lines

if my description of your scenario above was correct, you have a couple of options:

(a) get an additional /30 public IP space to use between the outside of the firewall and the inside of your router

(b) subnet your existing /26 and steal a /30 out of it from the beginning or end of the range for the network between the firewall and router

(c) use an RFC 1918 network for the network between the firewall and router

Is there any chance of

d) use something like PPPoE on the external interface of the firewall, which would mean you could use the existing IP ranges without modification?

Not that I really know if/how this would work, asking the question to learn rather than to advise....

Quoted 1 line

the "best" solution is A, but will cost some extra $$$.

How come? Do ISPs tend to charge for IP space these days?

Quoted 6 lines

C can cause problems if certain situations. B is a nice compromise, basically it would involve:

router:

	inside interface:  207.145.24.129/30
	static route:      207.145.24.128/26 via 207.145.24.130

Will the router support this? You're telling it that 207.145.24.130 is on the local network on the other side of its inside interface, and on the other side of 207.145.24.130... in a way. I'm not sure, this just looks, well, icky.

Quoted 4 lines

firewall:

	outside interface:  207.145.24.130/30
	inside interface:   207.145.24.190/26
	default gateway:    207.145.24.129

Yes, but where's 207.145.24.129? It falls within the network on both interfaces. I expect the firewall will route traffic the correct way because its the most specific route, but I don't like the idea of doing this with directly connected networks.

Quoted 2 lines

default gateway of hosts on the 207.145.24.128/26 network:
207.145.24.190

This will work... except no internal hosts will be able to talk to the router directly... which might be OK, but for management and monitoring everything will have to come from the firewall. As all the hosts think that everything from 207.145.24.129-190 is on the local network they will arp for 207.145.24.129 - the router - rather than sending the traffic to the firewall.

Signature · 1 line
Recedite, plebes! Gero rem imperialem!
#3 lore raw
Quoted 7 lines · Nick Drage

If you've got 128 public IPS doesn't that mean you want a netmask of 255.255.255.128? Alternatively 255.255.255.192 is a /26, giving you 207.145.24.129 to 207.145.24.190?

http://jodies.de/ipcalc

is your friend :)

typo. then i continued to use it for the rest of my example. sorry for the confusion.

Quoted 3 lines

I think the original poster meant connections outbound... at least I hope so, inbound port 80 connections to all hosts is probably a bad idea.

depends whether you read minds better than i do. since he said "hosting company" i assumed all the traffic he was trying to allow was inbound.

Quoted 5 lines
Quoted 2 lines
Quoted 2 lines

and I would also like to specify certain
ports for certain ips for dns, ftp, remote desktop, etc.

Then again - OP, any chance for some clarification?

Quoted 7 lines

<snip>

Is there any chance of

d) use something like PPPoE on the external interface of the firewall, which would mean you could use the existing IP ranges without modification?

that would probably fall under C. not sure why PPPoE would be necessary for that.

Quoted 6 lines

Not that I really know if/how this would work, asking the question to learn rather than to advise....

Quoted 1 line

the "best" solution is A, but will cost some extra $$$.

How come? Do ISPs tend to charge for IP space these days?

yes. nobody rides for free.

Quoted 11 lines
Quoted 6 lines

C can cause problems if certain situations. B is a nice compromise, basically it would involve:

router:

	inside interface:  207.145.24.129/30
	static route:      207.145.24.128/26 via 207.145.24.130

Will the router support this? You're telling it that 207.145.24.130 is on the local network on the other side of its inside interface, and on the other side of 207.145.24.130... in a way. I'm not sure, this just looks, well, icky.

icky as it may look, it's called Variable Length Subnet Masking (VLSM):

http://www.tcpipguide.com/free/t_IPVariableLengthSubnetMaskingVLSM.htm

Quoted 7 lines
Quoted 4 lines

firewall:

	outside interface:  207.145.24.130/30
	inside interface:   207.145.24.190/26
	default gateway:    207.145.24.129

Yes, but where's 207.145.24.129? It falls within the network on both interfaces.

it's on the outside interface. longest prefix length route always win. both the firewall and router know this. the hosts on the inside will be the ones that assume 129 - 131 are on the same network as them. this would be the "icky" part.

Quoted 9 lines

I expect the firewall will route traffic the correct way because its the most specific route, but I don't like the idea of doing this with directly connected networks.

Quoted 2 lines

default gateway of hosts on the 207.145.24.128/26 network:
207.145.24.190

This will work... except no internal hosts will be able to talk to the router directly...

um--that the point. i'm not sure if i actually understood the OP's question--i was answering "how do i stick a layer 3 firewall into an existing network where all hosts use the router as the default gateway."

if the hosts could talk to the router directly--there wouldn't be much point in having the firewall.

Quoted 2 lines

which might be OK, but for management and monitoring everything will have to come from the firewall.

why?

Quoted 4 lines

As all the hosts think
that everything from 207.145.24.129-190 is on the local network they will arp for 207.145.24.129 - the router - rather than sending the traffic to the firewall.

the firewall is their default gateway (190)--they don't need to talk to the router. if something needs to talk to the router directly (for SNMP mgmt or something) add a static route to it that points 207.145.24.128/30 via 207.145.24.190.

again--i was only trying to explain the option that actually required a lengthy explanation. the best solution is still A.

-j

Signature · 1 line
Jason Opperisano <[email protected]>
#4 lore raw
Quoted 4 lines · Jason Opperisano
Quoted 3 lines · Nick Drage

If you've got 128 public IPS doesn't that mean you want a netmask of 255.255.255.128? Alternatively 255.255.255.192 is a /26, giving you 207.145.24.129 to 207.145.24.190?

<snip>

Quoted 2 lines

typo. then i continued to use it for the rest of my example. sorry for the confusion.

The original poster said 255.255.255.192 for his netwask but said he has 128 public IPs... so the typo wasn't yours, I should have been clearer.

Quoted 6 lines
Quoted 3 lines

I think the original poster meant connections outbound... at least I hope so, inbound port 80 connections to all hosts is probably a bad idea.

depends whether you read minds better than i do. since he said "hosting company" i assumed all the traffic he was trying to allow was inbound.

That's a very good point :)

<snip>

Quoted 6 lines
Quoted 3 lines

d) use something like PPPoE on the external interface of the firewall, which would mean you could use the existing IP ranges without modification?

that would probably fall under C. not sure why PPPoE would be necessary for that.

I've probably misunderstood PPPoE. I thought it was possible to have

      <----- External IP
Router
  | 
  |  Some kind of layer two magic where all traffic that isn't for the
  |  hosts themselves is passed between the router and the firewall
  |

Firewall
| <-----Internal IP
|
Internal network

Where "PPPoE" is the "layer two magic", effectively the Router and Firewall are one device as far as layer 3 is concerned, and pass all traffic not meant for themselves to the other device.

<snip>

Quoted 7 lines
Quoted 7 lines
Quoted 6 lines

C can cause problems if certain situations. B is a nice compromise, basically it would involve:

router:

	inside interface:  207.145.24.129/30
	static route:      207.145.24.128/26 via 207.145.24.130
Quoted 8 lines
Quoted 4 lines

Will the router support this? You're telling it that 207.145.24.130 is on the local network on the other side of its inside interface, and on the other side of 207.145.24.130... in a way. I'm not sure, this just looks, well, icky.

icky as it may look, it's called Variable Length Subnet Masking (VLSM):

http://www.tcpipguide.com/free/t_IPVariableLengthSubnetMaskingVLSM.htm

Heh, I'm familiar with VLSM, but I've never seen overlapping subnets before... well, not overlapping subnets relating to networks directly connected to a device.

Quoted 8 lines
Quoted 2 lines

This will work... except no internal hosts will be able to talk to the router directly...

um--that the point. i'm not sure if i actually understood the OP's question--i was answering "how do i stick a layer 3 firewall into an existing network where all hosts use the router as the default gateway."

Quoted 7 lines

if the hosts could talk to the router directly--there wouldn't be much point in having the firewall.

Quoted 2 lines

which might be OK, but for management and monitoring everything will have to come from the firewall.

why?

Sorry, as you point out, this is a hosting company, so I would expect that none of the servers need to talk to the router, any hosts set up to monitor it will be elsewhere.

As for the last bit, "will have to come from the firewall" should be "will have to come from a host that is not behind the firewall", which does open up the range of possible hosts rather a lot.

Quoted 11 lines
Quoted 3 lines

As all the hosts think that everything from 207.145.24.129-190 is on the local network they will arp for 207.145.24.129 - the router - rather than sending the traffic to the firewall.

the firewall is their default gateway (190)--they don't need to talk to the router. if something needs to talk to the router directly (for SNMP mgmt or something) add a static route to it that points 207.145.24.128/30 via 207.145.24.190.

again--i was only trying to explain the option that actually required a lengthy explanation. the best solution is still A.

Thanks for the explanation, it makes sense to me now... Joe?

Signature · 1 line
Recedite, plebes! Gero rem imperialem!