LinuxQuestions.org
Help answer threads with 0 replies.
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 07-18-2006, 02:50 AM   #1
PetruM
LQ Newbie
 
Registered: Apr 2006
Location: Sweden
Distribution: Slackware, Ubuntu 22.04 LTS
Posts: 19

Rep: Reputation: Disabled
Question iptables on Ubuntu 6.06 Server


Hello.

I am running Ubuntu 6.06 Server on a small webserver. I am trying to secure the box and allow only two IPs to connect via SSH. My iptables rules are as following:

Code:
iptables -F
iptables -F -t nat
iptables -A INPUT -i lo -j ACCEPT
iptables -A OUTPUT -o lo -j ACCEPT
iptables -A INPUT -p tcp -s 1.2.3.4 --dport 22 -j ACCEPT
iptables -A INPUT -p tcp -s 1.2.3.5 --dport 22 -j ACCEPT
iptables -A INPUT -p tcp --dport 22 -j DROP
iptables -A FORWARD -p tcp --dport 445 -j DROP
iptables -A FORWARD -p tcp --sport 445 -j DROP
iptables -A FORWARD -p udp --dport 445 -j DROP
iptables -A FORWARD -p udp --sport 445 -j DROP
iptables -A FORWARD -p tcp --dport 135:139 -j DROP
iptables -A FORWARD -p tcp --sport 135:139 -j DROP
iptables -A FORWARD -p udp --dport 135:139 -j DROP
iptables -A FORWARD -p udp --sport 135:139 -j DROP
Of course, I have replaced 1.2.3.4 and 1.2.3.5 with the real IP addresses. So my question is: is this enough to prevent everyone else from getting into the server? I made a shell script with these rules and added it in /etc/init.d, is this right to add something at startup?

Any help is greatly appreciated.
 
Old 07-18-2006, 10:46 AM   #2
seneschal
LQ Newbie
 
Registered: Jul 2006
Location: Minnesota
Distribution: RHEL, Debian, Ubuntu
Posts: 27

Rep: Reputation: 15
As a general rule, it's best to set a firewall to default deny, then add rules allowing traffic through. I would do something more like this:
Code:
iptables -F
iptables -F -t nat
iptables -A INPUT -p tcp --dport 22 -s 1.2.3.4 -j ACCEPT
iptables -A INPUT -p tcp --dport 22 -s 1.2.3.5 -j ACCEPT
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -P INPUT DROP
The ESTABLISHED,RELATED line is critical. If you leave it out, then traffic related to existing connections will be blocked. Assuming that you don't want to forward any traffic, add this line:
Code:
iptables -P FORWARD DROP
Adding a startup script to Ubuntu is accomplished by adding the script to /etc/init.d/ then running update-rc.d.
 
Old 07-18-2006, 11:57 AM   #3
PetruM
LQ Newbie
 
Registered: Apr 2006
Location: Sweden
Distribution: Slackware, Ubuntu 22.04 LTS
Posts: 19

Original Poster
Rep: Reputation: Disabled
Thanks for the help.
What's the syntax for update-rc.d? If I type just 'update-rc.d' it displays help.

Last edited by PetruM; 07-18-2006 at 12:03 PM.
 
Old 07-19-2006, 12:18 AM   #4
seneschal
LQ Newbie
 
Registered: Jul 2006
Location: Minnesota
Distribution: RHEL, Debian, Ubuntu
Posts: 27

Rep: Reputation: 15
Say you have /etc/init.d/firewall - you would run:
Code:
update-rc.d firewall defaults
I recommend checking out man pages and such to make sure that you won't be putting this into any runlevels you might not want. Also, one other things that occurs to me is allowing traffic from loopback. You should probably add this line (or something like it) to your firewall script:
Code:
iptables -A INPUT -i lo -s 127.0.0.1 -d 127.0.0.1 -j ACCEPT

Last edited by seneschal; 07-19-2006 at 12:20 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
Ubuntu Desktop vs. Ubuntu Server Joe Donner Ubuntu 20 04-10-2013 04:20 AM
Setting up Ubuntu LAMP Server for local web server sewmyheadon Linux - Newbie 5 02-11-2007 03:06 PM
Help Setting Up Mail Server In Ubuntu Server 5.10 twaern Ubuntu 1 05-19-2006 07:22 PM
Ubuntu Server with Samba, Windows PC's cant access server! elliotfuller Linux - Networking 1 09-10-2005 07:40 AM
[IPTABLES] open ext access to web server on GW server kozaki Linux - Networking 3 08-27-2005 06:11 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Security

All times are GMT -5. The time now is 09:33 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
Open Source Consulting | Domain Registration