Review your favorite Linux distribution.
Go Back > Forums > Linux Forums > Linux - Networking
User Name
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.


  Search this Thread
Old 09-14-2009, 11:30 AM   #1
Registered: Dec 2006
Location: London, UK
Distribution: Centos, Fedora
Posts: 53

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

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

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

the 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 and then send it out through, at the same time changing the source ip to 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.

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

Rep: Reputation: 124Reputation: 124
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 -j MASQUERADE
Old 09-14-2009, 06:56 PM   #3
Registered: Dec 2006
Location: London, UK
Distribution: Centos, Fedora
Posts: 53

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 -j SNAT --to-source

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.


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 > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 03:49 AM.

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