LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
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-24-2006, 07:14 AM   #1
Sushy
Member
 
Registered: Sep 2005
Distribution: FreeBSD
Posts: 84

Rep: Reputation: 15
how to NAT ip to LAN


Hi!

I have 5 ip static addresses (for ex. 0.0.0.1 - 5)
One of them uses my router box on eth0. (0.0.0.1)
I have LAN on eth1 (192.168.10.0/24)

BUT one of the users of the LAN needs to use this secon free static ip 0.0.0.2 on his pc in the LAN.

So how can I route/forward this IP? Is there any NAT or something rule ?

(I there is some need to know I`m using iptables + HLS (home lan security firewall)
Please help!!!

Thanks.
 
Old 07-24-2006, 11:56 AM   #2
NSWKim
LQ Newbie
 
Registered: Jul 2006
Distribution: Ubuntu
Posts: 22

Rep: Reputation: 15
Smile iptables - why yes

Hello Sushy,

Assuming those ip addresses never change (static) then you will probably want to enable IP_Forwarding and make a simple SNAT (secure nat) rule in iptables.

Something along these lines should do it:
Code:
echo "net.ipv4.ip_forward=1" >> /etc/sysctl.conf
sysctl -p
iptables -A FORWARD -i eth0 -o eth1 -s 192.168.10.0/24 -j ACCEPT
iptables -t nat -A POSTROUTING -o eth0 -s 192.168.10.0/24 -j SNAT --to-source 0.0.0.1
Obviously you may need to change the ip's if those aren't what you're actually using, and be sure to use iptables-save to keep those settings upon reboot :-)
 
Old 07-24-2006, 05:42 PM   #3
win32sux
LQ Guru
 
Registered: Jul 2003
Location: Los Angeles
Distribution: Ubuntu
Posts: 9,870

Rep: Reputation: 377Reputation: 377Reputation: 377Reputation: 377
Quote:
Originally Posted by NSWKim
iptables -A FORWARD -i eth0 -o eth1 -s 192.168.10.0/24 -j ACCEPT
iptables -t nat -A POSTROUTING -o eth0 -s 192.168.10.0/24 -j SNAT --to-source 0.0.0.1
i'd make a small tweak to this suggestion, as it would not work with the FORWARD chain's policy set to DROP (as it should be)... also, there's a typo with the -i and -o interfaces (they should be inverted)... here's my tweaked suggestion:
Code:
iptables -P FORWARD DROP

iptables -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT

iptables -A FORWARD -i eth1 -o eth0 -s 192.168.10.0/24 \
-m state --state NEW -j ACCEPT

iptables -t nat -A POSTROUTING -o eth0 -s 192.168.10.0/24 \
-j SNAT --to-source 0.0.0.1
just my ...
 
  


Reply


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
What FireWall & NAT for home LAN? fipeso Linux - Newbie 6 04-19-2005 03:41 PM
WiFi LAN and NAT - seeking for advice dom_lochet Linux - Wireless Networking 3 01-26-2005 06:55 AM
NAT for lan 192.168.2.x urukhay Linux - Networking 1 11-09-2004 05:49 AM
RH 9 : Enable My LAN to Access TFTP Server Using NAT mr13stu Linux - Networking 0 02-19-2004 04:14 PM
What's the difference between Linux-NAT and Sygate-NAT? yuzuohong Linux - Networking 0 08-07-2002 05:07 AM

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

All times are GMT -5. The time now is 12:45 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration