+ Post New Thread
Page 1 of 2 12 LastLast
Results 1 to 15 of 24
*nix Thread, Setting up NAT using IPTABLES in Technical; Im trying to set up nat on one of my Linux boxes. I have read a few guides and have ...
  1. #1
    ChrisH's Avatar
    Join Date
    Jun 2005
    Location
    East Lancs
    Posts
    5,013
    Thank Post
    120
    Thanked 283 Times in 261 Posts
    Rep Power
    108

    Setting up NAT using IPTABLES

    Im trying to set up nat on one of my Linux boxes. I have read a few guides and have even remembered the free oreilly book I got free once with something "Linux iptables Pocket Reference" .

    I want to start simple with just setting nat up for now and locking the ports down more later.
    From what ive seen I need to use a SNAT rule and enable forwarding. This needs to be run as a script on startup from /etc/init.d
    Given that eth0 is public and eth1 is private:

    The script will contain the following:
    Delete all current rules:
    Code:
    /sbin/iptables -F
    /sbin/iptables -t nat -F
    /sbin/iptables -t mangle -F #ignore if you get an error here
    /sbin/iptables -X #deletes every non-builtin chain in the table
    Rules to allow all connections out and existing and related ones in:

    Code:
    /sbin/iptables -A FORWARD -i eth0 -o eth1 -m state --state ESTABLISHED,RELATED -j ACCEPT
    /sbin/iptables -A FORWARD -i eth1 -o eth0 -j ACCEPT
    The actual NAT rule where 10.0.0.1 is the address of eth0
    Code:
    /sbin/iptables -t nat -A POSTROUTING -o eth0 -j SNAT --to 10.0.0.1
    Then enable packet forwarding by kernel
    Code:
    echo 1 > /proc/sys/net/ipv4/ip_forward
    Does this look right? I seem to be reading confilcting stuff so just want to make sure.

  2. #2

    Geoff's Avatar
    Join Date
    Jun 2005
    Location
    Fylde, Lancs, UK.
    Posts
    11,804
    Thank Post
    110
    Thanked 583 Times in 504 Posts
    Blog Entries
    1
    Rep Power
    224

    Re: Setting up NAT using IPTABLES

    yes, that looks correct. However rather than writing your iptables rules directly you might find using a set of premade scripts like Shorewall is less likely to lead to serious brain ache.

    http://www.shorewall.net/

  3. #3
    ChrisH's Avatar
    Join Date
    Jun 2005
    Location
    East Lancs
    Posts
    5,013
    Thank Post
    120
    Thanked 283 Times in 261 Posts
    Rep Power
    108

    Re: Setting up NAT using IPTABLES

    Aye I have looked at other pre made stuff but just wanted to do a bit manually so I could understand it better.

  4. #4

    Geoff's Avatar
    Join Date
    Jun 2005
    Location
    Fylde, Lancs, UK.
    Posts
    11,804
    Thank Post
    110
    Thanked 583 Times in 504 Posts
    Blog Entries
    1
    Rep Power
    224

    Re: Setting up NAT using IPTABLES

    Fair enough. Be careful though if your playing with a live system. You can do serious damage to your networks routing and security.

    I use shorewall on all my systems these days. I'm lazy and it works. Plus I don't have to audit it for security because its done for me by the shorewall community.

  5. #5
    ChrisH's Avatar
    Join Date
    Jun 2005
    Location
    East Lancs
    Posts
    5,013
    Thank Post
    120
    Thanked 283 Times in 261 Posts
    Rep Power
    108

    Re: Setting up NAT using IPTABLES

    Well as long as I know that code would work I I understand most of it so.... Times a ticking so I will got with the shorewall

  6. #6

    Geoff's Avatar
    Join Date
    Jun 2005
    Location
    Fylde, Lancs, UK.
    Posts
    11,804
    Thank Post
    110
    Thanked 583 Times in 504 Posts
    Blog Entries
    1
    Rep Power
    224

    Re: Setting up NAT using IPTABLES

    You can always look at the rulechains shorewall produces from your configuration. thats usually fairly educational.

  7. #7
    ChrisH's Avatar
    Join Date
    Jun 2005
    Location
    East Lancs
    Posts
    5,013
    Thank Post
    120
    Thanked 283 Times in 261 Posts
    Rep Power
    108

    Re: Setting up NAT using IPTABLES

    Oh btw I set your quakenet account to +ao in the #edugeek channel. I will get the ident stuff sorted tonight then apply for a trusted IP.

  8. #8

    Geoff's Avatar
    Join Date
    Jun 2005
    Location
    Fylde, Lancs, UK.
    Posts
    11,804
    Thank Post
    110
    Thanked 583 Times in 504 Posts
    Blog Entries
    1
    Rep Power
    224

    Re: Setting up NAT using IPTABLES

    Fair enough. If you have trouble with the trust give me a shout. I know a few IRCOps that owe me favors. Also, I have an eggdrop floating around. So if you want a bot to police the channel against usual lameness (floods, spam, control avalanches) then I can bring him in too.

  9. #9
    ChrisH's Avatar
    Join Date
    Jun 2005
    Location
    East Lancs
    Posts
    5,013
    Thank Post
    120
    Thanked 283 Times in 261 Posts
    Rep Power
    108

    Re: Setting up NAT using IPTABLES

    Been playing with shorewall for a bit and have got the hang of it just about. I have downloaded the two-interface example and Im using that. Only problem is it ignores everything in the policy file and I have to make all changes in the rules file :? . I havent even touched it really aprt from uncomment the bit about giving users access to all port internally.

  10. #10

    Geoff's Avatar
    Join Date
    Jun 2005
    Location
    Fylde, Lancs, UK.
    Posts
    11,804
    Thank Post
    110
    Thanked 583 Times in 504 Posts
    Blog Entries
    1
    Rep Power
    224

    Re: Setting up NAT using IPTABLES

    did you define your interfaces?

  11. #11
    ChrisH's Avatar
    Join Date
    Jun 2005
    Location
    East Lancs
    Posts
    5,013
    Thank Post
    120
    Thanked 283 Times in 261 Posts
    Rep Power
    108

    Re: Setting up NAT using IPTABLES

    The interfaces look ok in the predefined set that came with the example I downloaded so I havent altered it.

  12. #12

    Geoff's Avatar
    Join Date
    Jun 2005
    Location
    Fylde, Lancs, UK.
    Posts
    11,804
    Thank Post
    110
    Thanked 583 Times in 504 Posts
    Blog Entries
    1
    Rep Power
    224

    Re: Setting up NAT using IPTABLES

    So you've correctly associated the right interface with the right zone?

  13. #13
    ChrisH's Avatar
    Join Date
    Jun 2005
    Location
    East Lancs
    Posts
    5,013
    Thank Post
    120
    Thanked 283 Times in 261 Posts
    Rep Power
    108

    Re: Setting up NAT using IPTABLES

    Yes just checked the zones file and the interface file seem to be set as they should be. I assume it always knows fw is the local machine and that it doesnt need setting anywhere?

  14. #14

    Geoff's Avatar
    Join Date
    Jun 2005
    Location
    Fylde, Lancs, UK.
    Posts
    11,804
    Thank Post
    110
    Thanked 583 Times in 504 Posts
    Blog Entries
    1
    Rep Power
    224

    Re: Setting up NAT using IPTABLES

    Does your external interface use a public internet IP or are you natted out somehow by your provider? Is your internal network using an RFC1918 compatible network range?

  15. #15
    ChrisH's Avatar
    Join Date
    Jun 2005
    Location
    East Lancs
    Posts
    5,013
    Thank Post
    120
    Thanked 283 Times in 261 Posts
    Rep Power
    108

    Re: Setting up NAT using IPTABLES

    Network 192.168.0.0/23---------- 192.168.0.0/23 Firewall 10.x.x.x --> Cleo Router.

    Is my current setup.

SHARE:
+ Post New Thread
Page 1 of 2 12 LastLast

Similar Threads

  1. iptables multiple ports
    By Jackd in forum *nix
    Replies: 1
    Last Post: 23rd December 2007, 10:19 PM
  2. Proxy setting GPO
    By LOUD in forum Wireless Networks
    Replies: 1
    Last Post: 11th December 2007, 08:35 AM
  3. Setting Up New Server and New Domain
    By Zoom7000 in forum Windows
    Replies: 14
    Last Post: 2nd June 2007, 08:16 PM
  4. Setting up a new network
    By wesleyw in forum How do you do....it?
    Replies: 16
    Last Post: 12th March 2007, 09:57 AM
  5. AB Tutor setting
    By eastlondon in forum Windows
    Replies: 0
    Last Post: 29th September 2006, 11:46 AM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •