LinuxQuestions.org
Review your favorite Linux distribution.
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 10-24-2011, 03:43 PM   #1
savona
Member
 
Registered: Mar 2011
Location: Bellmawr, NJ
Distribution: Red Hat / Fedora
Posts: 215

Rep: Reputation: 66
Forward packets with iptables


I am looking to forward packets to a proxy server from a machine that does not have access to the proxy. The proxy operates on port 80.

If you look at my rather crude drawing below you will see the basic setup of my network. I need machine #2 to forward all packets on port 80 and port 443 coming from machine 1 to proxy:80.

Obviously I also need that packets to make it back to machine #1.

Anyway I can do this with IPTABLES? Any help would be greatly appreciated.
Attached Thumbnails
Click image for larger version

Name:	drawing.jpg
Views:	52
Size:	22.3 KB
ID:	8240  
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 10-25-2011, 03:45 AM   #2
lqman
LQ Newbie
 
Registered: Nov 2010
Location: Surabaya, Indonesia
Distribution: debian, ubuntu, FreeBSD, Solaris
Posts: 17

Rep: Reputation: 3
Yes, you can do it with iptables.

Use iptables to setting up port-forwarding on machine#2 to forward all tcp request (dst-port 80 & 443) originate from machine#1 to proxy:80
 
Old 10-25-2011, 07:17 AM   #3
savona
Member
 
Registered: Mar 2011
Location: Bellmawr, NJ
Distribution: Red Hat / Fedora
Posts: 215

Original Poster
Rep: Reputation: 66
Quote:
Originally Posted by lqman View Post
Yes, you can do it with iptables.

Use iptables to setting up port-forwarding on machine#2 to forward all tcp request (dst-port 80 & 443) originate from machine#1 to proxy:80
Thanks but how can I do that?
 
Old 10-27-2011, 03:46 AM   #4
simonmcnair
LQ Newbie
 
Registered: Oct 2011
Posts: 17

Rep: Reputation: Disabled
you could try this, modified to suit your needs. It works on mine, but then I'm not trying to tunnel IPSEC so your mileage may vary.

iptables --append FORWARD --in-interface br0 -j ACCEPT
iptables -t nat -A POSTROUTING -o eth1 -j SNAT --to-source 10.10.10.1
 
Old 10-27-2011, 03:49 AM   #5
simonmcnair
LQ Newbie
 
Registered: Oct 2011
Posts: 17

Rep: Reputation: Disabled
and don't forget
sysctl -w net.ipv4.ip_forward=1

/etc/sysctl.conf:
net.ipv4.ip_forward = 1
 
Old 10-27-2011, 03:55 AM   #6
simonmcnair
LQ Newbie
 
Registered: Oct 2011
Posts: 17

Rep: Reputation: Disabled
ooooh, I forgot. I posted about an online iptables generator the other day :-)

https://plus.google.com/100303566317...ts/MwzeZbpHzci

Simon
 
Old 10-27-2011, 11:00 PM   #7
lqman
LQ Newbie
 
Registered: Nov 2010
Location: Surabaya, Indonesia
Distribution: debian, ubuntu, FreeBSD, Solaris
Posts: 17

Rep: Reputation: 3
I assume your ip sec tun interface is tun0.

iptables -t nat -A PREROUTING -i tun0 -p tcp --dport 80 -j DNAT --to 192.168.1.12:80
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE


and as simonmcnair said, don't forget to set ip_forwarding
sysctl -w net.ipv4.ip_forward=1

Last edited by lqman; 10-28-2011 at 12:39 AM.
 
Old 10-28-2011, 12:37 AM   #8
lqman
LQ Newbie
 
Registered: Nov 2010
Location: Surabaya, Indonesia
Distribution: debian, ubuntu, FreeBSD, Solaris
Posts: 17

Rep: Reputation: 3
I assume your ip sec tun interface is tun0.

iptables -t nat -A PREROUTING -i tun0 -s 10.0.0.6 -p tcp --dport 80 -j DNAT --to 192.168.1.12:80
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE


and as simonmcnair said, don't forget to set ip_forwarding
sysctl -w net.ipv4.ip_forward=1

Last edited by lqman; 10-28-2011 at 12:40 AM.
 
2 members found this post helpful.
Old 10-31-2011, 03:52 AM   #9
fhleung
Member
 
Registered: Aug 2004
Distribution: Lubuntu Live OS
Posts: 432

Rep: Reputation: 30
Hi folks,

I got similar question and hope to get feedback. I had no proxy box but instead was router so only 2 boxes.
Again, what I want is: machine#2 to forward packets from machine#1 and vice versa

From the diagram, machine#2 had 2 NIC,
assume eth0 connect to proxy,
and eth1 connect to machines#1 which private ip is 10.0.0.6

Code:
machine#2 ifconfig -a
eth0 inet 192.168.1.13

eth1 inet UNKNOWN
My first question was: the private ip/inet UNKNOWN of eth1 has to be same class like 10.0.x.y?
Can it be 192.168.*.* ?

Last edited by fhleung; 10-31-2011 at 04:01 AM.
 
Old 11-08-2011, 02:09 AM   #10
fhleung
Member
 
Registered: Aug 2004
Distribution: Lubuntu Live OS
Posts: 432

Rep: Reputation: 30
Quote:
Originally Posted by lqman View Post
I assume your ip sec tun interface is tun0.
iptables -t nat -A PREROUTING -i tun0 -s 10.0.0.6 -p tcp --dport 80 -j DNAT --to 192.168.1.12:80
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
Only above two iptables statements would WORK?
Need the iptables FORWARD chain statement?
 
Old 11-09-2011, 08:35 PM   #11
lqman
LQ Newbie
 
Registered: Nov 2010
Location: Surabaya, Indonesia
Distribution: debian, ubuntu, FreeBSD, Solaris
Posts: 17

Rep: Reputation: 3
Quote:
Only above two iptables statements would WORK?
Need the iptables FORWARD chain statement?
Yes it works in savona case.
Try to adjust it for your case.

No need FORWARD chain statement.
 
  


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 rules to NAT or FORWARD packets between LAN clients templeton Linux - Networking 5 11-28-2010 09:00 AM
IPTables Static NAT, 2 networks, unable to forward packets to Port 80 CommanderKang Linux - Networking 1 08-27-2010 03:35 PM
How to get packets into the forward chain? marting Linux - Server 2 09-17-2008 02:15 AM
How can I forward ports with IPtables? I want to forward 80 to 8080 abefroman Linux - Networking 3 05-23-2008 10:05 AM
iptables: forcing packets for FORWARD dombrowsky Linux - Networking 6 10-15-2006 11:09 AM

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

All times are GMT -5. The time now is 02:12 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