Access to Internal server via public address
Anyone,
The Problem: I have an alias public address DNAT'ed to and internal
address - normal and working
What i need is to access this server using the PUBLIC address from an
internal workstation. What I have:
INTNIC = eth1 EXTNIC = eth0 INTERNALNET = 192.168.20.0/24 FIREALLIP = 1.2.3.4 DNATADDR = 1.2.3.5
/sbin/iptables -I FORWARD -p tcp -i eth0 -o eth1 -d 192.168.20.0/24
--dport 22 -j ACCEPT
/sbin/iptables -t nat -A PREROUTING -p tcp -d 1.2.3.5 -s !
192.168.20.0/24 --dport 22 -j DNAT 192.168.20.22:22
I also have a SNAT for masquerading everyting going out
/sbin/iptables -t nat -A POSTROUTING -s 192.168.20.0/24 -o eth0 -j SNAT
--to-source 1.2.3.4
I have searched for a solutions longer than I care to admit. Can
anyone give me an example on how to allow an internal ip address access to another internal address via the DNAT'ed public address.
Vernon Fort
Quoted 21 lines · Vernon A. Fort
Anyone,
The Problem: I have an alias public address DNAT'ed to and internal
address - normal and workingWhat i need is to access this server using the PUBLIC address from an
internal workstation. What I have:INTNIC = eth1 EXTNIC = eth0 INTERNALNET = 192.168.20.0/24 FIREALLIP = 1.2.3.4 DNATADDR = 1.2.3.5
/sbin/iptables-I FORWARD -p tcp -i eth0 -o eth1 -d 192.168.20.0/24
--dport 22 -j ACCEPT
/sbin/iptables-t nat -A PREROUTING -p tcp -d 1.2.3.5 -s !
192.168.20.0/24 --dport 22 -j DNAT 192.168.20.22:22
Quoted 8 lines
I also have a SNAT for masquerading everyting going out
/sbin/iptables -t nat -A POSTROUTING -s 192.168.20.0/24 -o eth0 -j SNAT--to-source 1.2.3.4
I have searched for a solutions longer than I care to admit. Can
anyone give me an example on how to allow an internal ip address access to another internal address via the DNAT'ed public address.
You need to SNAT as well as DNAT so that the reply packets come back through the netfilter machine.
http://www.netfilter.org/documentation/HOWTO/NAT-HOWTO-10.html
Ideally you should have the SSH server on a DMZ - then it would be accessible by public IP from both outside and inside without any fuss :)
Antony.
Signature · 10 lines
In science, one tries to tell people
in such a way as to be understood by everyone
something that no-one ever knew before.
In poetry, it is the exact opposite.
- Paul Dirac
Please reply to the list;
please don't CC me.Good afternoon, Vernon,
Quoted 21 lines · Vernon A. Fort
Anyone,
The Problem: I have an alias public address DNAT'ed to and internal
address - normal and workingWhat i need is to access this server using the PUBLIC address from an
internal workstation. What I have:INTNIC = eth1 EXTNIC = eth0 INTERNALNET = 192.168.20.0/24 FIREALLIP = 1.2.3.4 DNATADDR = 1.2.3.5
/sbin/iptables-I FORWARD -p tcp -i eth0 -o eth1 -d 192.168.20.0/24
--dport 22 -j ACCEPT
/sbin/iptables-t nat -A PREROUTING -p tcp -d 1.2.3.5 -s !
192.168.20.0/24 --dport 22 -j DNAT 192.168.20.22:22
Quoted 8 lines
I also have a SNAT for masquerading everyting going out
/sbin/iptables -t nat -A POSTROUTING -s 192.168.20.0/24 -o eth0 -j SNAT--to-source 1.2.3.4
I have searched for a solutions longer than I care to admit. Can
anyone give me an example on how to allow an internal ip address access to another internal address via the DNAT'ed public address.
If the client box and the internal server in question are on the
same cable, you essentially can't do this direcdtly (but read on).
Picture this as a triangle; the internal machines on the bottom,
(client left, server right) and the firewall at the top. The packets physically all travel over the same Ethernet segment shared by all three machines, I'm just demonstrating who's talking to whom.
Internet
^
|
Firewall
/ \
(1) / \ (2)
/ \
/ \
Client---Server192.168.20.99 (3) 192.168.20.22
The Client creates a syn packet to the server and sends it to its
default gateway, the firewall:
Packet (1): 192.168.20.99 -> 1.2.3.5 (SYN)
The firewall applies DNAT to it, replacing the destination IP with
the internal address of the Server:
Packet (2): 192.168.20.99 -> 192.168.20.22 (SYN)
The server sees this and creates a SYN/ACK packet going back to
the client:
Packet (3): 192.168.20.22 -> 192.168.20.99 (SYN/ACK)
, which it then ships out its ethernet cable _directly_ to
192.168.20.99 _without going through the firewall first_! Because of this, the firewall never has a chance to fix the source address of the SYN/ACK packet.
The client gets the SYN/ACK, looks at the IP addresses, and says,
"Excuse me, I wasn't talking to your port 22, go away" with a RST packet, because the client still thinks it's talking to 1.2.3.5. It's sorely mistaken. :-)
There are a number of potential fixes for this.
The most elegant - and the best one from a security standpoint
because it moves servers off the cable holding your client machines - is to move all servers off onto another ethernet segment. Something like:
Internet
^
|
Firewall-------------------....
| | |
| Server1 Server2
|
|
+-----+--------....
| |
Client1 Client2
Now the packets flowing in both directions are seen by the firewall, and so it has a chance to fix the server address on packets going back to the client.
A second approach which is worth considering is simply editing the
hosts table on the internal machines to have the line:
192.168.20.22 shell.myco.com
(replace /etc/hosts with the appropriate resolution file for other
OS's, or even consider running a separate internal dns server). Now, when I run "ssh shell.myco.com", I go directly to the right IP address (even though DNS claims shell.myco.com is at 1.2.3.5). You can even make this manual change for SSH in ~/.ssh/config with a section like:
Host shell.myco.com
Hostname 192.168.20.22 HostKeyAlias shell.myco.com , which overrides whatever hosts/dns says when the user literally
types "ssh shell.myco.com". Obviously, this approach is appliation specific.
A third, less preferred, approach is to _also_ do _SNAT_ on
packets heading to that server, replacing the client IP with the firewall's internal IP address. Now the server thinks it's responding back to the _firewall_, shipping packets to it, allowing it to fix both the source _and_ destination addresses in both directions. Picture the first ascii art diagram with no direct link between server and client; packets 1 and 2 are the same, the Packet (3) syn ack goes back over the same path as (2), the firewall fixes source and destination addresses, and sends a doubly mangled SYN/ACK Packet (4) back over the same path as (1).
The catch here is that the server can no longer identify _which_
internal system is talking to it; all connections from internal machines (and the entire world if you don't write the SNAT rule correctly) all look like they're coming from 192.168.20.1 (assuming that's the firewall IP address). This makes effective IP based access control impossible in tp wrappers on the server. I'll avoid the flamewar on whether it was truly effective in the first place, thanks. ;-)
Cheers,
- Bill
---------------------------------------------------------------------------
"Immortality is an adequate definition of high availability for
me."
--- Gregory F. Pfister
(Courtesy of Lars Marowsky-Bree <[email protected]>)
--------------------------------------------------------------------------
William Stearns ([email protected]). Mason, Buildkernel, freedups, p0f,
rsync-backup, ssh-keyinstall, dns-check, more at: http://www.stearns.org
Linux articles at: http://www.opensourcedigest.com
--------------------------------------------------------------------------
Quoted 11 lines · William Stearns
Good afternoon, Vernon,
Quoted 7 lines · Vernon A. Fort
Anyone,
The Problem: I have an alias public address DNAT'ed to and internal
address - normal and workingWhat i need is to access this server using the PUBLIC address from an
internal workstation.
Quoted 7 lines
If the client box and the internal server in question are on the
same cable, you essentially can't do this direcdtly (but read on).Picture this as a triangle; the internal machines on the bottom,
(client left, server right) and the firewall at the top. The packets physically all travel over the same Ethernet segment shared by all three machines, I'm just demonstrating who's talking to whom.
Excellent answer, Bill.
I think this explains a common situation (and a common FAQ) in more detail,
and with more information, than I've seen before. Hopefully it is clear to
a network non-expert as well (I don't use the term newbie here, because once you've got DNAT working at all, you've clearly gone beyond that stage...)
Your reply is (IMHO) worthy of a FAQ entry in itself.
Antony
Signature · 6 lines
What is this talk of "software release"?
Our software evolves and matures until it is capable of escape, leaving a
bloody trail of designers and quality assurance people in its wake.
Please reply to the list;
please don't CC me.Good afternoon, Anthony,
Quoted 13 lines · Antony Stone
Quoted 11 lines · William Stearns
Quoted 6 lines · Vernon A. Fort
The Problem: I have an alias public address DNAT'ed to and internal
address - normal and workingWhat i need is to access this server using the PUBLIC address from an
internal workstation.If the client box and the internal server in question are on the
same cable, you essentially can't do this direcdtly (but read on).
Quoted 6 lines
Quoted 4 lines
Picture this as a triangle; the internal machines on the bottom,
(client left, server right) and the firewall at the top. The packets physically all travel over the same Ethernet segment shared by all three machines, I'm just demonstrating who's talking to whom.Excellent answer, Bill.
Thanks so much.
Quoted 6 lines
I think this explains a common situation (and a common FAQ) in more detail,
and with more information, than I've seen before. Hopefully it is clear to
a network non-expert as well (I don't use the term newbie here, because once you've got DNAT working at all, you've clearly gone beyond that stage...)Your reply is (IMHO) worthy of a FAQ entry in itself.
I suppose that's up to Harald, as he's the author of the FAQ and
there doesn't _appear_ to be sgml source for the Netfilter faq on the homepage. Harald, if you consider this worthy of a faq entry (look back a few in this thread) and can loan the the SGML source for a bit, I'd be glad to do the best I can on merging it in (but no promises on the ascii art!).
Cheers,
- Bill
---------------------------------------------------------------------------
"Industry wags are saying that God invented SCO to give people a
company to hate more than Microsoft."
-- http://www.linuxworld.com/story/38045.htm
--------------------------------------------------------------------------
William Stearns ([email protected]). Mason, Buildkernel, freedups, p0f,
rsync-backup, ssh-keyinstall, dns-check, more at: http://www.stearns.org
Linux articles at: http://www.opensourcedigest.com
--------------------------------------------------------------------------
Home web server using front firewall
All,
I am trying to install a small web server at home in order to display some family pictures and some other personal topics (hobbies, interests ...)
I would like to have the following configuration:
Static IP -------- Linux --------- Real web server SBC ADSL Firewall eth0 eth1 63.5.5.5 10.10.1.5
For this I need port forwarding and probably NAT to change the outgoing IP address.
I want the real server to be completely blocked for any other port than http and https on the web server (I am planning to accept requests only from the internal network).
If you can shed some light on the port forwarding part, I think I can tackle the rest. I believe it would be something like this:
iptables -P INPUT DROP
iptables -P OUTPUT DROP
iptables -P FORWARD DROP
iptables -t nat -A PREROUTING -p tcp -d 63.5.5.5 \
--dport 80 -j DNAT --to 10.10.1.5
iptables -t nat -A PREROUTING -p tcp -d 63.5.5.5 \
--dport 443 -j DNAT --to 10.10.1.5
iptables -A FORWARD -i eth1 -s 10.10.1.0/24 --sport 80 \
-j ACCEPT
iptables -A FORWARD -i eth1 -s 10.10.1.0/24 --sport 443 \
-j ACCEPT
iptables -A POSTROUTING -t nat -o eth0 -j MASQUERADEI am already dropping all malformed packets before this entries, so nmap and nessus should not be able to do attacks; they will be able to tell there is a web server there, but that is all.
Also, I am planning to use syn_cookies to avoid DoS attacks.
Am I forgetting anything else?
Beforehand, thank you for your help.
PS. if someone has something like this working, could you please send me your config?
Re: Home web server using front firewall
Quoted 8 lines · Erick Sanz
All,
I am trying to install a small web server at home in order to display some family pictures and some other personal topics (hobbies, interests ...)
For this I need port forwarding and probably NAT to change the outgoing IP address.
If you do DNAT for incoming packets, you will get automatic SNAT on the outgoing reply packets - you do not need to set up your own rule to handle these.
Quoted 4 lines
I want the real server to be completely blocked for any other port than http and https on the web server (I am planning to accept requests only from the internal network).
Um, do you really mean what that last bit says? You only want to accept
requests from the internal network - ie not from the Internet???
Quoted 1 line
Am I forgetting anything else?
The only thing I can see missing from the rules you posted is:
iptables -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
That rule will allow the reply packet to traverse your firewall, and return to the outside world (assuming that's what you really want to happen....).
If you have any problems with the ruleset you posted (with the above addition) feel free to post here again, but please be as specific as you can about what the problem is, and how you have tested for it.
Hope you have a good time with netfilter.
Antony.
Signature · 7 lines
Success is a lousy teacher. It seduces smart people into thinking they can't
lose.
- William H Gates III
Please reply to the list;
please don't CC me.Quoted 8 lines · William Stearns
Quoted 1 line
Your reply is (IMHO) worthy of a FAQ entry in itself.
I suppose that's up to Harald, as he's the author of the FAQ and
there doesn't _appear_ to be sgml source for the Netfilter faq on the homepage. Harald, if you consider this worthy of a faq entry (look back a few in this thread) and can loan the the SGML source for a bit, I'd be glad to do the best I can on merging it in (but no promises on the ascii art!).
sgml has always been in the documentation/FAQ subdirectory of the CVS tree.
Quoted 2 lines
Cheers,
- Bill
Signature · 5 lines
- Harald Welte <[email protected]> http://www.netfilter.org/ ============================================================================ "Fragmentation is like classful addressing -- an interesting early architectural error that shows how much experimentation was going on while IP was being designed." -- Paul Vixie
RE: Home web server using front firewall
In reply to Antony StoneAnthony,
This are the entries I had to add to make it work:
iptables -P INPUT DROP
iptables -P OUTPUT DROP
iptables -P FORWARD DROP
iptables -t nat -A PREROUTING -p tcp -d 172.16.1.33 --dport 80 \ -j DNAT --to 10.10.1.240
iptables -A POSTROUTING -t nat -o eth0 -j MASQUERADE
iptables -A INPUT -i eth0 -p tcp -d 172.16.1.33 --dport 80 -m state \
--state NEW,ESTABLISHED,RELATED -j ACCEPT
iptables -A INPUT -i eth1 -p tcp -s 10.10.1.240 --sport 80 -m state \
--state ESTABLISHED,RELATED -j ACCEPT
iptables -A FORWARD -i eth0 -p tcp -d 10.10.1.240 --dport 80 -m state \
--state NEW,ESTABLISHED,RELATED -j ACCEPT
iptables -A FORWARD -i eth1 -p tcp -s 10.10.1.0/24 --source-port 80 \
-j ACCEPT
iptables -A FORWARD -o eth1 -p tcp -s 10.10.1.240 --sport 80 -m state \
--state NEW,ESTABLISHED,RELATED -j ACCEPT
iptables -A OUTPUT -o eth1 -j ACCEPT
I have read the FAQ on forwarding; however, I can still not understand the 3 forwarding statements needed; one of them is for input on eth0 (172.16.1.33) to 10.10.1.240. The other one is for data received from eth1 (10.10.1.240); however, I don't understand the third forward (can't be taken out as it won't work then)... I see the difference as -i to -o ... Is there a newby explanation on why?
Also, I would like to "lock" my OUTPUT chain to avoid Netbios and other protocols to go out... any recommendations?
Thank you VERY much for your time!
Best regards,
Erick Sanz
Quoted 67 lines
-----Original Message-----
From: [email protected] [mailto:[email protected]]On Behalf Of Antony Stone
Sent: Wednesday, December 10, 2003 5:40 PM
To: Netfilter
Subject: Re: Home web server using front firewallQuoted 8 lines · Erick Sanz
All,
I am trying to install a small web server at home in order to display some family pictures and some other personal topics (hobbies, interests ...)
For this I need port forwarding and probably NAT to change the outgoing IP address.
If you do DNAT for incoming packets, you will get automatic SNAT on the outgoing reply packets - you do not need to set up your own rule to handle
these.Quoted 4 lines
I want the real server to be completely blocked for any other port than http and https on the web server (I am planning to accept requests only from the internal network).
Um, do you really mean what that last bit says? You only want to accept
requests from the internal network - ie not from the Internet???Quoted 1 line
Am I forgetting anything else?
The only thing I can see missing from the rules you posted is:
iptables -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
That rule will allow the reply packet to traverse your firewall, and return to
the outside world (assuming that's what you really want to happen....).If you have any problems with the ruleset you posted (with the above addition)
feel free to post here again, but please be as specific as you can about what
the problem is, and how you have tested for it.Hope you have a good time with netfilter.
Antony.
--
Success is a lousy teacher. It seduces smart people into thinking they can't
lose.- William H Gates III
Please reply
to the list;
please
don't CC me.
Quoted 3 lines
This email message has been scanned for viruses.
This email message has been scanned for viruses.
Re: Home web server using front firewall
Quoted 8 lines
iptables -A FORWARD -i eth0 -p tcp -d 10.10.1.240 --dport 80 -m state \
--state NEW,ESTABLISHED,RELATED -j ACCEPTiptables -A FORWARD -i eth1 -p tcp -s 10.10.1.0/24 --source-port 80 \
-j ACCEPTiptables -A FORWARD -o eth1 -p tcp -s 10.10.1.240 --sport 80 -m state \
--state NEW,ESTABLISHED,RELATED -j ACCEPT
The first forward allows inbound traffic from eth0 (net?) to hit the webserver on 10.10.1.240
The second forward allows any traffic FROM any webserver in the 10.10.1.0/24 network out to anywhere (ODD!)
The third forward specifically allows the web server at 10.10.1.240 to respond to web requests, and should be redundant with the second rule
Here's my question -- which interface is which? Assuming eth0 is the internet side, and eth1 is your DMZ side, you should have these:
iptables -A FORWARD -i eth0 -p tcp -d 10.10.1.240 --dport 80 -j ACCEPT iptables -A FORWARD -i eth1 -p tcp -s 10.10.1.240 --sport 80 -m state --state ESTABLISHED,RELATED -j ACCEPT
and that should do it.
Are you logging dropped packets?
Quoted 2 lines
Also, I would like to "lock" my OUTPUT chain to avoid Netbios and other protocols to go out... any recommendations?
To drop netbios (137-139 tcp & udp), you'd probably want to drop it going out AND being forwarded, like this:
iptables -A FORWARD -o eth0 -p tcp --dport 137 -j DROP iptables -A FORWARD -o eth0 -p tcp --dport 138 -j DROP iptables -A FORWARD -o eth0 -p tcp --dport 139 -j DROP iptables -A FORWARD -o eth0 -p udp --dport 137 -j DROP iptables -A FORWARD -o eth0 -p udp --dport 138 -j DROP iptables -A FORWARD -o eth0 -p udp --dport 139 -j DROP iptables -A OUTPUT -o eth0 -p tcp --dport 137 -j DROP iptables -A OUTPUT -o eth0 -p tcp --dport 138 -j DROP iptables -A OUTPUT -o eth0 -p tcp --dport 139 -j DROP iptables -A OUTPUT -o eth0 -p udp --dport 137 -j DROP iptables -A OUTPUT -o eth0 -p udp --dport 138 -j DROP iptables -A OUTPUT -o eth0 -p udp --dport 139 -j DROP
Quoted 1 line
Thank you VERY much for your time!
You get what you pay for... lol
Re: Home web server using front firewall
In reply to Erick SanzQuoted 11 lines · Erick Sanz
Antony,
This are the entries I had to add to make it work:
iptables -P INPUT DROP
iptables -P OUTPUT DROP
iptables -P FORWARD DROPiptables -t nat -A PREROUTING -p tcp -d 172.16.1.33 --dport 80 \ -j DNAT --to 10.10.1.240
Quoted 7 lines
iptables -A POSTROUTING -t nat -o eth0 -j MASQUERADE
iptables -A INPUT -i eth0 -p tcp -d 172.16.1.33 --dport 80 -m state \
--state NEW,ESTABLISHED,RELATED -j ACCEPTiptables -A INPUT -i eth1 -p tcp -s 10.10.1.240 --sport 80 -m state \
--state ESTABLISHED,RELATED -j ACCEPT
Packets being routed through a firewall from one side to the other do not go through the INPUT chain.
The only packets which go through rules in the INPUT chain are those addressed to the firewall itself, and not being routed any further.
I do not believe you need the above two rules in the INPUT chain.
Quoted 6 lines
I have read the FAQ on forwarding; however, I can still not understand the 3 forwarding statements needed; one of them is for input on eth0 (172.16.1.33) to 10.10.1.240. The other one is for data received from eth1 (10.10.1.240); however, I don't understand the third forward (can't be taken out as it won't work then)... I see the difference as -i to -o ... Is there a newby explanation on why?
You need to understand the difference between putting a rule in the INPUT chain (which is for packets addressed to the firewall itself), compared to specifying -i in a rule in the FORWARD chain (which is for packets being routed through the firewall, where you want to specify which interface they entered the machine through).
Here's a suggestion:
Allow your firewall to pass some of the traffic that you want (now that you've got it working), and then type:
iptables -L -n -v -x
You will see each of the rules in the INPUT, FORWARD and OUTPUT rules, with byte and packet counts at the beginning.
Any rule which has a zero packet / byte count has not seen any traffic, and is therefore not contributing to your firewall working.
Hopefully this helps to explain things a bit more so you understand what is needed and what is not.
Antony.
Signature · 2 lines
This is not a rehearsal. This is Real Life.