LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 07-08-2011, 04:35 AM   #1
blueblood
LQ Newbie
 
Registered: Jul 2011
Posts: 5

Rep: Reputation: Disabled
Iptables - NAT


I've finished my test this morning. There is a question that I don't know exactly the way to solve. Hope someone here can help me solve out.

There are 3 PCs and one Proxy Server connect to firewall in network 172.16.1.0/16. Firewall has 2 interface.

Internal interface: eth0 with ip address 172.16.1.1
External interface: eth1 IP 10.0.0.1

How to let Proxy server connects to Internet through firewall? And how to let other PCs connect to Internet through Proxy Server?

Last edited by blueblood; 07-08-2011 at 04:37 AM.
 
Old 07-08-2011, 05:27 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
OK, well you probably don't want a standard NAT, and you also want to enable ip forwarding on the firewall. BTW, You've not mentioned the word "Linux" in any of this... this IS a linux firewall, right?? This will get the routing / natting sorted:

sysctl -w net.ipv4.ip_forward=1 (edit this in /etc/sysctl.conf to make it permanent.
iptables -t nat -A POSTROUTING -s 172.16.1.XXX -o eth1 -j MASQUERADE

Where XXX is the proy server IP. After that you will still want responsible firewall rules to control the access in general.

Last edited by acid_kewpie; 07-08-2011 at 05:31 AM.
 
1 members found this post helpful.
Old 07-08-2011, 08:11 AM   #3
blueblood
LQ Newbie
 
Registered: Jul 2011
Posts: 5

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by acid_kewpie View Post
OK, well you probably don't want a standard NAT, and you also want to enable ip forwarding on the firewall. BTW, You've not mentioned the word "Linux" in any of this... this IS a linux firewall, right?? This will get the routing / natting sorted:

sysctl -w net.ipv4.ip_forward=1 (edit this in /etc/sysctl.conf to make it permanent.
iptables -t nat -A POSTROUTING -s 172.16.1.XXX -o eth1 -j MASQUERADE

Where XXX is the proy server IP. After that you will still want responsible firewall rules to control the access in general.
yes, it is linux firewall. thank you for your fast reply.

I did exactly what you tell in this post for letting only Proxy Server connect to Internet through firewall. And let other PCs connect to Internet through Proxy Server (they can't connect directly to Internet), I add the following rule:

iptables -A INPUT -d 172.16.1.XXX -p all -j ACCEPT (XXX is the proxy server IP)

Is is OK? I'm totally not sure about this
 
Old 07-08-2011, 08:17 AM   #4
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
well that as a rule by itself will work - Oh no, you've got -d (destination) instead of is (source) for the proxy so you'd want to change that, but if it's appended it may be after a default deny so wouldn't get reached etc. "iptables -vnL" will show the full ruleset in context. I would not advise allowing *everything* through from it. From its role as a proxy it should only need tcp ports 80 and 443. You should also only be permitted new traffic explicitly on that rule, but that's something of a subtlety that won't affect you right now.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
IPTables 1:1 NAT Garak Linux - Security 13 12-19-2011 05:03 PM
iptables and NAT gardenair Linux - Newbie 2 12-02-2010 12:42 AM
iptables: can't initialize iptables table `NAT' linuxgentoo Linux - Kernel 3 01-17-2010 10:15 AM
IPTABLES : build NAT using IPTABLES joseph Linux - Networking 4 04-23-2004 05:08 AM
iptables and NAT arrruken Linux - Networking 8 10-03-2003 04:17 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 02:29 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration