LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Security
User Name
Password
Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.

Notices

Reply
 
Search this Thread
Old 12-01-2007, 04:02 AM   #1
sunlinux
Member
 
Registered: Feb 2006
Distribution: RHCL 5
Posts: 226

Rep: Reputation: 30
iptables outbound traffic to all ports


Hi,

I configured NAT on linux box.

I want to allow a lan ip to connect all incomming n all outgoing traffic on destination ip(internet ip) both tcp n udp on all ports.

Pls. help me out.
 
Old 12-01-2007, 10:46 AM   #2
win32sux
Guru
 
Registered: Jul 2003
Location: Los Angeles
Distribution: Ubuntu
Posts: 9,870

Rep: Reputation: 371Reputation: 371Reputation: 371Reputation: 371
Well, to let the LAN IP connect to the WAN IP in only TCP and UDP protocols it's like:
Code:
iptables -P FORWARD DROP

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

iptables -A FORWARD -p TCP -i $LAN_IFACE -o $WAN_IFACE -s $LAN_IP -d $WAN_IP \
-m state --state NEW -j ACCEPT

iptables -A FORWARD -p UDP -i $LAN_IFACE -o $WAN_IFACE -s $LAN_IP -d $WAN_IP \
-m state --state NEW -j ACCEPT
Then to forward all TCP and UDP traffic from that WAN IP to the LAN IP (DMZ style) it's like:
Code:
iptables -t nat -A PREROUTING -p TCP -i $WAN_IFACE -j DNAT --to-destination $LAN_IP

iptables -t nat -A PREROUTING -p UDP -i $WAN_IFACE -j DNAT --to-destination $LAN_IP

iptables -A FORWARD -p TCP -i $WAN_IFACE -o $LAN_IFACE -s $WAN_IP -d $LAN_IP \
-m state --state NEW -j ACCEPT

iptables -A FORWARD -p UDP -i $WAN_IFACE -o $LAN_IFACE -s $WAN_IP -d $LAN_IP \
-m state --state NEW -j ACCEPT

iptables -t nat -A POSTROUTING -o $WAN_IFACE -j MASQUERADE
Keep in mind this would all be somewhat simpler if you'd just match everything instead of just TCP and UDP:
Code:
iptables -P FORWARD DROP

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

iptables -A FORWARD -i $LAN_IFACE -o $WAN_IFACE -s $LAN_IP -d $WAN_IP \
-m state --state NEW -j ACCEPT

iptables -t nat -A PREROUTING -i $WAN_IFACE -j DNAT --to-destination $LAN_IP

iptables -A FORWARD -i $WAN_IFACE -o $LAN_IFACE -s $WAN_IP -d $LAN_IP \
-m state --state NEW -j ACCEPT

iptables -t nat -A POSTROUTING -o $WAN_IFACE -j MASQUERADE

Last edited by win32sux; 12-01-2007 at 11:08 AM.
 
  


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
Blocking specific outbound traffic - iptables mistersnorfles Linux - Security 5 08-08-2007 02:14 PM
Anyone know if IPCOPS can filter outbound traffic? lumix Linux - Security 1 03-25-2007 01:23 PM
are outbound ports converged while local ports are ok ? inanc Linux - Networking 0 02-06-2007 10:37 AM
Excessive Outbound Traffic chandramani Linux - Security 1 01-29-2006 11:03 AM
Spike in outbound traffic- where to look? htmlcoder Linux - Security 3 03-19-2005 03:13 PM


All times are GMT -5. The time now is 11:02 AM.

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