Iptables
Hi,
I'm new to iptables and having a problem grasping the concept as well as the syntax. I have read a lot of sites on this but just not getting it. First - running rules. From what I can gather I need to have an rc.firewall file with the various rules and such in it - and have this started at boot. Am I close? Second - the syntax. I want to be able to allow my local LAN full access to the Linux box (Slackware 10). I also have a website which I want to allow everyone - except for a few domains and IP's, SSH which I want to allow only certain IP's or domains, and Samba which I want to allow only my local LAN. This is where I'm really confused putting this all together. If someone could explain this in plain english - or put me on to a really easy iptables for dummies type site, it would be appreciated.
This box is behind attached to a Linksys router and does not act as a NAT. It is just a simple little setup on a p166.
Thanks
Quoted 6 lines · [email protected] wrote:
Hi,
I'm new to iptables and having a problem grasping the concept as well as the syntax. I have read a lot of sites on this but just not getting it. First - running rules. From what I can gather I need to have an rc.firewall file with the various rules and such in it - and
The filename depends on your system and/or what you define to be a startup script.
Quoted 3 lines
have this started at boot. Am I close? Second - the syntax. I want to be able to allow my local LAN full access to the Linux box (Slackware 10). I also have a website which I want to allow everyone
Ah. Slack. Yes, if you put a rc.firewall file in /etc/rc.d and do a "chmod 700 rc.firewall" there, it will start at boot (if I read rc.inet2 correctly).
Quoted 9 lines
- except for a few domains and IP's, SSH which I want to allow only certain IP's or domains, and Samba which I want to allow only my local LAN. This is where I'm really confused putting this all together. If someone could explain this in plain english - or put me on to a really easy iptables for dummies type site, it would be appreciated.
This box is behind attached to a Linksys router and does not act as a NAT. It is just a simple little setup on a p166.
Okay. You want to close your box as much as possible :
iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -P OUTPUT ACCEPT # because in the beginning it will cause \
# you headaches if you DROP this
Next, allow related and established connections :
iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT iptables -A FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT
Allow full access from LAN :
iptables -A INPUT -i <if_lan> -s <net_lan> -j ACCEPT
Allow access to website (running on the firewall box I assume) :
iptables -A INPUT -i <if_inet> -s <ip_to_deny> -p tcp --dport 80 \
-j DROP
...Repeat for any disallowed host...
iptables -A INPUT -i <if_inet> -p tcp --dport 80 -j ACCEPT
Allow access to SSH :
iptables -A INPUT -i <if_inet> -s <ip_allowed_host> -p tcp \
--dport 22 -j ACCEPT
...Repeat for any allowed host...
You already opened up your box for your LAN. That includes Samba so you don't need a rule for this.
Do you also want internet access for your LAN clients ? iptables -A FORWARD -i <if_lan> -o <if_inet> -s <net_lan> \
-j ACCEPT
iptables -t nat -A POSTROUTING -o <if_inet> -s <net_lan> \
-j SNAT --to-source <ip_inet>A good reading site includes Oskar's :
http://iptables-tutorial.frozentux.net/iptables-tutorial.html
Gr,
Rob
This helps a bit, but still way out of my league - there is a lot of stuff to remember. In the many sites, including the one you list below, they talk of various configurations before ever getting to the rules - is this necessary?
i.e.
INET_IP="194.236.50.155"
INET_IFACE="eth0"
INET_BROADCAST="194.236.50.255"
LAN_IP="192.168.0.2"
LAN_IP_RANGE="192.168.0.0/16"
LAN_IFACE="eth1"
Then a bunch of modules are loaded....
Are <if_lan>, <net_lan> and <if_inet> reserved commands or do I need to put something in here. I am assuming these are variables and tie in with the above - not sure though.
Note: All the other LAN clients have access to the internet via the Linksys router as does the Linux box. The router is my gateway....
One last thing. Is there a way to block an entire domain i.e. domain.com or an entire IP block i.e 24.168.1.0/24.
Thanks
Quoted 85 lines
-----Original Message-----
From: Rob Sterenborg [mailto:[email protected]]
Sent: September 28, 2004 1:25 AM
To: 'Contact'; [email protected].
Subject: RE: IptablesQuoted 3 lines · [email protected] wrote:
Hi,
I'm new to iptables and having a problem grasping the
concept as well
Quoted 1 line
as the syntax. I have read a lot of sites on this but just
not getting
Quoted 2 lines
it. First - running rules. From what I can gather I need to have an rc.firewall file with the various rules and such in it - and
The filename depends on your system and/or what you define to be a startup script.
Quoted 1 line
have this started at boot. Am I close? Second - the
syntax. I want to
Quoted 1 line
be able to allow my local LAN full access to the Linux box
(Slackware
Quoted 1 line
10). I also have a website which I want to allow everyone
Ah. Slack. Yes, if you put a rc.firewall file in
/etc/rc.dand do a "chmod 700 rc.firewall" there, it will start at boot (if I read rc.inet2 correctly).Quoted 2 lines
- except for a few domains and IP's, SSH which I want to allow only certain IP's or domains, and Samba which I want to allow
only my local
Quoted 1 line
LAN. This is where I'm really confused putting this all
together. If
Quoted 1 line
someone could explain this in plain english - or put me on
to a really
Quoted 3 lines
easy iptables for dummies type site, it would be appreciated.
This box is behind attached to a Linksys router and does
not act as a
Quoted 1 line
NAT. It is just a simple little setup on a p166.
Okay. You want to close your box as much as possible :
iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -P OUTPUT ACCEPT # because in the beginning it will cause \# you headaches if you DROP thisNext, allow related and established connections :
iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT iptables -A FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPTAllow full access from LAN :
iptables -A INPUT -i <if_lan> -s <net_lan> -j ACCEPTAllow access to website (running on the firewall box I assume) :
iptables -A INPUT -i <if_inet> -s <ip_to_deny> -p tcp --dport 80 \
-j DROP
...Repeat for any disallowed host...
iptables -A INPUT -i <if_inet> -p tcp --dport 80 -j ACCEPTAllow access to SSH :
iptables -A INPUT -i <if_inet> -s <ip_allowed_host> -p tcp \
--dport 22 -j ACCEPT
...Repeat for any allowed host...You already opened up your box for your LAN. That includes Samba so you don't need a rule for this.
Do you also want internet access for your LAN clients ? iptables -A FORWARD -i <
if_lan> -o <if_inet> -s <net_lan> \
-j ACCEPTiptables -t nat -A POSTROUTING -o <if_inet> -s <net_lan> \ -j SNAT --to-source <ip_inet>A good reading site includes Oskar's :
http://iptables-tutorial.frozentux.net/iptables-tutorial.htmlGr,
Rob
Quoted 7 lines · Contact
This helps a bit, but still way out of my league - there is a lot of stuff to remember. In the many sites, including the one you list below, they talk of various configurations before ever getting to the rules - is this necessary?
i.e.
Quoted 7 lines
INET_IP="194.236.50.155"
INET_IFACE="eth0"
INET_BROADCAST="194.236.50.255"LAN_IP="192.168.0.2"
LAN_IP_RANGE="192.168.0.0/16"
LAN_IFACE="eth1"
necessary, no. but it is a standard scripting practice that makes your life easier. would you rather specify "eth0" 50 times in your script, and then have to change it 50 times when something hardware-wise changes? or just change one thing that says "INET_IF=eth0"
Quoted 1 line
Then a bunch of modules are loaded....
almost all modules are loaded automatically as needed by the kernel. you should explicitly load "helper" modules that you expect to need; i.e.,
modprobe ip_conntrack_ftp
modprobe ip_nat_ftp
Quoted 3 lines
Are <
if_lan>, <net_lan> and <if_inet> reserved commands or do I need to put something in here. I am assuming these are variables and tie in with the above - not sure though.
there are no such reserved words/commands with respect to iptables. it simply does what you tell it to.
Quoted 5 lines
Note: All the other LAN clients have access to the internet via the Linksys router as does the Linux box. The router is my gateway....
One last thing. Is there a way to block an entire domain i.e. domain.com or an entire IP block i.e 24.168.1.0/24.
domain--no, not really.
IP block--yes:
-s 24.168.1.0/24
-d 24.168.1.0/24Quoted 1 line
Thanks
no prob. i know it's already been recommended once, but you ready should hit this up and down:
http://iptables-tutorial.frozentux.net/iptables-tutorial.html
-j
Signature · 1 line
Jason Opperisano <[email protected]>
Quoted 10 lines · Contact
This helps a bit, but still way out of my league - there is a lot of stuff to remember. In the many sites, including the one you list below, they talk of various configurations before ever getting to the rules - is this necessary?
i.e.
INET_IP="194.236.50.155"
INET_IFACE="eth0"
INET_BROADCAST="194.236.50.255"
Those are variables in shell script. Basically they are there to make your life easier when you need to modify something. These two will do the same:
iptables -A INPUT -i eth0 .....
INET_IFACE="eth0"
iptables -A INPUT -i "$INET_IFACE" .....
Quoted 1 line
Then a bunch of modules are loaded....
Most of them you don't need to load by hand (they'll get loaded automatically). There are few exceptions, such as ip_nat_ftp module that needs to be loaded explicitly (if you need it, that is).
Quoted 3 lines
Are <
if_lan>, <net_lan> and <if_inet> reserved commands or do I need to put something in here. I am assuming these are variables and tie in with the above - not sure though.
Those are the places in Rob's examples where you need to fill in your data. For example you would chage <if_inet> to eth0 or "$INET_IFACE".
Quoted 2 lines
One last thing. Is there a way to block an entire domain i.e. domain.com or an entire IP block i.e 24.168.1.0/24.
You can block only by IP address (host or network). You can't block by domain name (which would be an useless feature even if it was possible, lurking people into false sense of security).
Signature · 3 lines
Aleksandar Milivojevic <[email protected]> Pollard Banknote Limited Systems Administrator 1499 Buffalo Place Tel: (204) 474-2323 ext 276 Winnipeg, MB R3T 1L7
Quoted 14 lines · Contact
Hi,
I'm new to iptables and having a problem grasping the concept as well as the syntax. I have read a lot of sites on this but just not getting it. First - running rules. From what I can gather I need to have an rc.firewall file with the various rules and such in it - and have this started at boot. Am I close? Second - the syntax. I want to be able to allow my local LAN full access to the Linux box (Slackware 10). I also have a website which I want to allow everyone - except for a few domains and IP's, SSH which I want to allow only certain IP's or domains, and Samba which I want to allow only my local LAN. This is where I'm really confused putting this all together. If someone could explain this in plain english - or put me on to a really easy iptables for dummies type site, it would be appreciated.
Quoted 5 lines
This box is behind attached to a Linksys router and does not act as a NAT. It is just a simple little setup on a p166.
Thanks
I found Oskar Andreasson's tutorial most helpful
(http://iptables-tutorial.frozentux.net/iptables-tutorial.html). You can also find some slightly dated slide show training sessions at
http://iscs.sourceforge.net Good luck - John
Signature · 5 lines
John A. Sullivan III Chief Technology Officer Nexus Management +1 207-985-7880 [email protected]
Quoted 14 lines · Contact
Hi,
I'm new to iptables and having a problem grasping the concept as well as the syntax. I have read a lot of sites on this but just not getting it. First - running rules. From what I can gather I need to have an rc.firewall file with the various rules and such in it - and have this started at boot. Am I close? Second - the syntax. I want to be able to allow my local LAN full access to the Linux box (Slackware 10). I also have a website which I want to allow everyone - except for a few domains and IP's, SSH which I want to allow only certain IP's or domains, and Samba which I want to allow only my local LAN. This is where I'm really confused putting this all together. If someone could explain this in plain english - or put me on to a really easy iptables for dummies type site, it would be appreciated.
Quoted 5 lines
This box is behind attached to a Linksys router and does not act as a NAT. It is just a simple little setup on a p166.
Thanks
Read the Iptables Tutorial from
http://iptables-tutorial.frozentux.net/iptables-tutorial.html
it explains everything you want to do and more.
Signature · 12 lines
Jose Maria Lopez Hernandez Director Tecnico de bgSEC [email protected] bgSEC Seguridad y Consultoria de Sistemas Informaticos http://www.bgsec.com ESPAÑA The only people for me are the mad ones -- the ones who are mad to live, mad to talk, mad to be saved, desirous of everything at the same time, the ones who never yawn or say a commonplace thing, but burn, burn, burn like fabulous yellow Roman candles. -- Jack Kerouac, "On the Road"