[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Insert IPTABLES rule

Posted on 2009-04-26
4
Medium Priority
?
1,535 Views
Last Modified: 2012-05-06
Hi guys, I am running iptables for a squid transparent proxy, and it is working fine. I have two questions:

1. On CentOS how do i ensure that this script auto runs at boot (script below).
2. How do I insert a rule into this script that will allow ssh access from a host to the squid proxy?
#!/bin/sh
# squid server IP
SQUID_SERVER="192.168.1.1"
# Interface connected to Internet
INTERNET="eth0"
# Interface connected to LAN
LAN_IN="eth1"
# Squid port
SQUID_PORT="3128"
 
# DO NOT MODIFY BELOW
# Clean old firewall
iptables -F
iptables -X
iptables -t nat -F
iptables -t nat -X
iptables -t mangle -F
iptables -t mangle -X
# Load IPTABLES modules for NAT and IP conntrack support
modprobe ip_conntrack
modprobe ip_conntrack_ftp
# For win xp ftp client
#modprobe ip_nat_ftp
echo 1 > /proc/sys/net/ipv4/ip_forward
# Setting default filter policy
iptables -P INPUT DROP
iptables -P OUTPUT ACCEPT
# Unlimited access to loop back
iptables -A INPUT -i lo -j ACCEPT
iptables -A OUTPUT -o lo -j ACCEPT
# Allow UDP, DNS and Passive FTP
iptables -A INPUT -i $INTERNET -m state --state ESTABLISHED,RELATED -j ACCEPT
# set this system as a router for Rest of LAN
iptables --table nat --append POSTROUTING --out-interface $INTERNET -j MASQUERADE
iptables --append FORWARD --in-interface $LAN_IN -j ACCEPT
# unlimited access to LAN
iptables -A INPUT -i $LAN_IN -j ACCEPT
iptables -A OUTPUT -o $LAN_IN -j ACCEPT
# DNAT port 80 request comming from LAN systems to squid 3128 ($SQUID_PORT) aka transparent proxy
iptables -t nat -A PREROUTING -i $LAN_IN -p tcp --dport 80 -j DNAT --to $SQUID_SERVER:$SQUID_PORT
# if it is same system
iptables -t nat -A PREROUTING -i $INTERNET -p tcp --dport 80 -j REDIRECT --to-port $SQUID_PORT
# DROP everything and Log it
iptables -A INPUT -j LOG
iptables -A INPUT -j DROP

Open in new window

0
Comment
Question by:dbtouraust
  • 2
  • 2
4 Comments
 
LVL 29

Expert Comment

by:fosiul01
ID: 24236151
In Centos you should have iptables install by defualt

you can add iptables rules from shell

then Save the rules

server iptables save

then resart iptables to make this work

service iptables restart

Or

you cann add that script in

/etc/rc.local file

so when system will boot, those rules will be add to the iptables automaticaly
0
 
LVL 1

Author Comment

by:dbtouraust
ID: 24236212
Thanks, but the question was more about the syntax for allowing ssh access from one host to another, in the above script.
0
 
LVL 29

Accepted Solution

by:
fosiul01 earned 1500 total points
ID: 24236386
Ok to allow ssh
add thise rules in your iptables
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
0
 
LVL 1

Author Closing Comment

by:dbtouraust
ID: 31574675
Thanks for the help, it worked!
0

Featured Post

A Cyber Security RX to Protect Your Organization

Join us on December 13th for a webinar to learn how medical providers can defend against malware with a cyber security "Rx" that supports a healthy technology adoption plan for every healthcare organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Envision that you are chipping away at another e-business site with a team of pundit developers and designers. Everything seems, by all accounts, to be going easily.
How to fix a SonicWall Gateway Anti-Virus firewall blocking automatic updates to apps like Windows, Adobe, Symantec, etc.
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses
Course of the Month19 days, 22 hours left to enroll

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question