LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 06-13-2010, 07:42 PM   #1
DigiCrime
Member
 
Registered: Dec 2002
Location: St. Louis
Distribution: All Flavors
Posts: 195

Rep: Reputation: 30
Nat routing


I setup a VPN yesterday and I set it up so internet traffic can be routed thru the VPN. I assigned different external IPs to different internal IPs the client connects with

10.9.0.3 > 64.xx.xx.179
10.9.0.4 > 64.xx.xx.175

And so on. Anyway I reboot the server yesterday and moved the listen IP to another IP for organizational reasons now my nat routing is not working anymore. Every client is connecting fine and getting out to the internet and into the server but their all stuck on the same external IP. Maybe I was seeing things but pretty sure I had it right...

iptables -t nat -A POSTROUTING -s 10.9.0.3/24 -j SNAT --to 64.xx.xx.179

service iptables save

Am I doing it right?

OpenVPN/CentOS 5.5
 
Old 06-14-2010, 03:59 AM   #2
centosboy
Senior Member
 
Registered: May 2009
Location: london
Distribution: centos5
Posts: 1,137

Rep: Reputation: 116Reputation: 116
Quote:
Originally Posted by DigiCrime View Post
I setup a VPN yesterday and I set it up so internet traffic can be routed thru the VPN. I assigned different external IPs to different internal IPs the client connects with

10.9.0.3 > 64.xx.xx.179
10.9.0.4 > 64.xx.xx.175

And so on. Anyway I reboot the server yesterday and moved the listen IP to another IP for organizational reasons now my nat routing is not working anymore. Every client is connecting fine and getting out to the internet and into the server but their all stuck on the same external IP. Maybe I was seeing things but pretty sure I had it right...

iptables -t nat -A POSTROUTING -s 10.9.0.3/24 -j SNAT --to 64.xx.xx.179

service iptables save

Am I doing it right?

OpenVPN/CentOS 5.5


They are all stuck on the same ip ??
Would it be this ip by any chance? 64.xx.xx.179
But then this is what your SNAT rule says....??
What if you had a rule for each ip address? Or change the SNAT range.

iptables -t nat -A POSTROUTING -o eth0 -j SNAT --to 1.2.3.4-1.2.3.25
 
Old 06-14-2010, 10:50 AM   #3
SuperJediWombat!
Member
 
Registered: Apr 2009
Location: Perth, Australia
Distribution: Ubuntu/CentOS
Posts: 208

Rep: Reputation: 51
The subnet mask for your source address should be /32 if you are doing a 1 to 1 SNAT.
Code:
iptables -t nat -A POSTROUTING -s 10.9.0.3/32 -j SNAT --to 64.xx.xx.179
 
Old 06-14-2010, 01:48 PM   #4
DigiCrime
Member
 
Registered: Dec 2002
Location: St. Louis
Distribution: All Flavors
Posts: 195

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by centosboy View Post
They are all stuck on the same ip ??
Would it be this ip by any chance? 64.xx.xx.179
But then this is what your SNAT rule says....??
What if you had a rule for each ip address? Or change the SNAT range.

iptables -t nat -A POSTROUTING -o eth0 -j SNAT --to 1.2.3.4-1.2.3.25
They are all stuck on .176 ip. I have 4 Ips on the server and I had the VPN listening on 179 but I moved it to 176 so I could access tbe web gui from a domain name. Anyway it outputs the same Ip on all clients. Internal IP is different of course but external Ip is the same.

Quote:
Originally Posted by SuperJediWombat! View Post
The subnet mask for your source address should be /32 if you are doing a 1 to 1 SNAT.
Code:
iptables -t nat -A POSTROUTING -s 10.9.0.3/32 -j SNAT --to 64.xx.xx.179
Tried that, still the same.
 
Old 06-14-2010, 02:08 PM   #5
nimnull22
Senior Member
 
Registered: Jul 2009
Distribution: OpenSuse 11.1, Fedora 14, Ubuntu 12.04/12.10, FreeBSD 9.0
Posts: 1,571

Rep: Reputation: 92
iptables -t nat -A POSTROUTING -s 10.9.0.3/24 -j SNAT --to 64.xx.xx.179

As long as I understand, this rule tells iptables to change something to 64.xx.xx.179 ONLY.


You can tell it to change like:
... -s 10.9.0.1/32 -j SNAT --to 64.xx.xx.179
... -s 10.9.0.2/32 -j SNAT --to 64.xx.xx.180
... -s 10.9.0.3/32 -j SNAT --to 64.xx.xx.181
 
Old 06-14-2010, 03:29 PM   #6
DigiCrime
Member
 
Registered: Dec 2002
Location: St. Louis
Distribution: All Flavors
Posts: 195

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by nimnull22 View Post
iptables -t nat -A POSTROUTING -s 10.9.0.3/24 -j SNAT --to 64.xx.xx.179

As long as I understand, this rule tells iptables to change something to 64.xx.xx.179 ONLY.


You can tell it to change like:
... -s 10.9.0.1/32 -j SNAT --to 64.xx.xx.179
... -s 10.9.0.2/32 -j SNAT --to 64.xx.xx.180
... -s 10.9.0.3/32 -j SNAT --to 64.xx.xx.181
Yup, that is what I am doing or how I would like it. Its not sticking however not sure why. How do I flush all my nat rules..
 
Old 06-15-2010, 03:12 AM   #7
SuperJediWombat!
Member
 
Registered: Apr 2009
Location: Perth, Australia
Distribution: Ubuntu/CentOS
Posts: 208

Rep: Reputation: 51
Code:
iptables -t nat -F
 
Old 06-15-2010, 03:58 AM   #8
centosboy
Senior Member
 
Registered: May 2009
Location: london
Distribution: centos5
Posts: 1,137

Rep: Reputation: 116Reputation: 116
Quote:
Originally Posted by DigiCrime View Post
Yup, that is what I am doing or how I would like it. Its not sticking however not sure why. How do I flush all my nat rules..
What do you mean by it is not sticking??
You add the rule, then check back again and it isnt there?
 
Old 06-18-2010, 07:30 PM   #9
DigiCrime
Member
 
Registered: Dec 2002
Location: St. Louis
Distribution: All Flavors
Posts: 195

Original Poster
Rep: Reputation: 30
edit: solved my own problem.

Last edited by DigiCrime; 06-22-2010 at 02:15 PM.
 
  


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
routing with NAT sunlinux Linux - Networking 3 07-01-2008 06:16 PM
Two-way NAT routing MPowers Linux - Networking 3 06-24-2005 03:24 PM
nat routing vaat Linux - Networking 11 02-16-2005 10:02 AM
real routing under nat routing nothingmuch Linux - Networking 4 10-27-2003 03:11 PM
Routing and nat Morning_Star Linux - Networking 5 02-11-2003 11:31 AM

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

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