LinuxQuestions.org
Visit Jeremy's Blog.
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 09-14-2009, 11:30 AM   #1
saiyen2002
Member
 
Registered: Dec 2006
Location: London, UK
Distribution: Centos, Fedora
Posts: 50

Rep: Reputation: 0
Question packet coming through one interface route out via another interface and SNAT also


I have box1 with ip 192.168.129.10 ang GW 192.168.129.1
This box also has an alias of 172.16.0.1

i have the ip of another box, box2 to 172.16.0.10 and the GW to 172.16.0.1, but box2 can not reach the internet. It can ping both ips of box1 but no internet.

the 172.16.0.0 network is not currently catered for in my company.

I am thinking that if i can create some iptable NAT rules on box1 that will accept any packets coming in on 172.16.0.1 and then send it out through 192.168.129.10, at the same time changing the source ip to 192.168.129.10 since 172.16.0 network is not catered for.

I dont know if my idea is possible, if it is how do i implement this on iptables.

If it doesn't work, other solutions are welcome.

thanks
 
Old 09-14-2009, 12:42 PM   #2
estabroo
Senior Member
 
Registered: Jun 2008
Distribution: debian, ubuntu, sidux
Posts: 1,094
Blog Entries: 2

Rep: Reputation: 111Reputation: 111
you need to turn on ip forwarding as well echo 1 > /proc/sys/net/ipv4/ip_forward (typically you can set it permanently in your sysctl.conf file)

then just add a rule like iptables -t nat -A POSTROUTING -o eth0 -s 172.16.0.10 -j MASQUERADE
 
Old 09-14-2009, 06:56 PM   #3
saiyen2002
Member
 
Registered: Dec 2006
Location: London, UK
Distribution: Centos, Fedora
Posts: 50

Original Poster
Rep: Reputation: 0
Thumbs up

It Works, thanks estabroo

I have modified it a little

iptables -t nat -A POSTROUTING -o eth0 -s 172.16.0.0/24 -j SNAT --to-source 192.168.129.1

from my scouring through the internet, masquerade is for dynamically assigned ip's and SNAT is better suited for static IP's.

Last edited by saiyen2002; 09-14-2009 at 08:10 PM.
 
  


Reply

Tags
iptables, routing


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
network interface not coming backup after reboot noir911 Linux - Server 2 02-10-2009 11:03 PM
SNAT with virtual interface not working rajat83 Linux - Networking 1 08-13-2008 11:34 PM
Route port 25 to interface eth2 ajaimes Linux - Networking 8 06-27-2007 02:39 AM
why i see same packet twice on network interface? cranium2004 Linux - Networking 6 11-26-2004 09:42 AM
How to get the IP header of packet going through an interface thanh Programming 1 06-12-2004 12:26 PM


All times are GMT -5. The time now is 04:45 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration