Web Hosting Talk


Go Back   Web Hosting Talk : Web Hosting Main Forums : Hosting Security and Technology : Iptables Rules
Reply

Hosting Security and Technology Configuring and optimizing web hosting servers and operating systems, developing administration scripts, building servers, protecting against hackers, and general security (SSL certificates, etc.)

 
Thread Tools Search this Thread Display Modes
  #1  
Old 07-02-2009, 05:57 PM
Ashley Merrick Ashley Merrick is offline
View Beta Profile
Premium Member
 
Join Date: Mar 2007
Location: UK
Posts: 625
Iptables Rules

Hello,

One of my low knowledge area's is Iptables Rule's I just normally use APF/CSF.

However on a VPS Host node, I basically want to block all access to a certain port let's say 1234 apart from a certain IP address.

However I don't want to block this port on any of the VPS's on the Node, so what Iptable Rule(s) would I need to put into a bash script on startup.

Thanks,
Ashley

Reply With Quote
Sponsored Links
  #2  
Old 07-02-2009, 06:00 PM
zacharooni zacharooni is offline
View Beta Profile
Web Hosting Master
 
Join Date: Apr 2005
Location: Lansing, MI
Posts: 1,092
If you're only blocking 1 IP address it will not block the port completely, just from that IP. You could use a rule like this:

/sbin/iptables -I INPUT -s IP.IP.IP.IP -d VPS.NODE.IP -m tcp -p tcp --dport 1234 -j DROP

__________________
My blog

Reply With Quote
  #3  
Old 07-02-2009, 08:39 PM
eeg3 eeg3 is offline
View Beta Profile
Junior Guru Wannabe
 
Join Date: Jul 2009
Location: Charlotte, NC
Posts: 42
I think (I could be wrong about his intentions) that he wants to block all access except from one IP address, in which case he would need to do:

Quote:
/sbin/iptables -I INPUT -d VPS.NODE.IP -m tcp -p tcp --dport 1234 -j DROP
/sbin/iptables -I INPUT -s IP.IP.IP.IP -d VPS.NODE.IP -m tcp -p tcp --dport 1234 -j ACCEPT
The above will put the ACCEPT for the IP.IP.IP.IP above the blanket DROP for everywhere else.

Reply With Quote
Sponsored Links
  #4  
Old 07-02-2009, 09:40 PM
zacharooni zacharooni is offline
View Beta Profile
Web Hosting Master
 
Join Date: Apr 2005
Location: Lansing, MI
Posts: 1,092
My apologies, I read that wrong the first time. You would want to do this:

Quote:
iptables -I INPUT -s IP.IP.IP.IP -d VPS.NODE.IP -m tcp -p tcp --dport 1234 -j ACCEPT
iptables -P INPUT DROP

__________________
My blog

Reply With Quote
  #5  
Old 07-02-2009, 10:27 PM
eeg3 eeg3 is offline
View Beta Profile
Junior Guru Wannabe
 
Join Date: Jul 2009
Location: Charlotte, NC
Posts: 42
Quote:
Originally Posted by zacharooni View Post
My apologies, I read that wrong the first time. You would want to do this:
That's going to block all input, and probably lock him out of the server.

Reply With Quote
  #6  
Old 07-02-2009, 11:38 PM
mugo mugo is offline
View Beta Profile
Intangible Asset Appraiser
 
Join Date: Mar 2009
Location: Austin Tx
Posts: 1,220
More than likely, if you are picking on a certain IP address, you will want to block them completely, not just a certain port

iptables -A INPUT -s 10.10.10.0/24 -j DROP

will blocks the whole /24, just drop the /24 and add last real octet to pick on the single IP.

Make it persistent
/sbin/service iptables save

I distribute a script to put offenders in, and it also optionally blocks certain foreign IPs (don't you get tired of all the APNIC brute forces and dDOSs?) for Linux and Win.
Helped cut down my spam too.

__________________
This is the best signature in the world....Tribute!
(It is not the best signature in the world, no. This is just a tribute)


Reply With Quote
  #7  
Old 07-03-2009, 12:35 AM
Rekhatitus Rekhatitus is offline
View Beta Profile
Junior Guru
 
Join Date: Jun 2009
Location: Kochi,India
Posts: 177
If you want to block a particular port on Hardware Node run the the following commands on HN. For eg: here we can consider port 9999 to be blocked
Quote:
iptables -I FORWARD -p tcp --dport 9999 -j DROP
iptables -I FORWARD -p udp --dport 9999 -j DROP
iptables -I FORWARD -p tcp --sport 9999 -j DROP
iptables -I FORWARD -p udp --sport 9999 -j DROP
and If you want to block a range of port say from 1234 to 2345

iptables -I FORWARD -p tcp --dport 1234:2345 -j DROP

__________________
Ezeelogin -
The ultimate multiple server administration software.
*Parallel shell *rm -rf protection *SSH logging*automated password changes*encrypted storage*
AdMod.com -Delivering innovative web hosting solutions

Reply With Quote
  #8  
Old 07-03-2009, 07:37 AM
khunj khunj is offline
View Beta Profile
Junior Guru
 
Join Date: Mar 2009
Location: /home/khunj
Posts: 185
Quote:
Originally Posted by Ashley Merrick View Post
I basically want to block all access to a certain port let's say 1234 apart from a certain IP address.
Use iptables negation [ ! ] :
Code:
# iptables -I INPUT -s ! xxx.xxx.xxx.xxx -p tcp --dport 1234 -j DROP
Reject any IP on port 1234 except xxx.xxx.xxx.xxx

Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes
Postbit Selector

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

Forum Jump
Login:
Log in with your username and password
Username:
Password:



Forgot Password?
Advertisement:

Similar Threads
Thread Thread Starter Forum Replies Last Post
ftpd and iptables rules robocap Hosting Security and Technology 6 05-20-2008 09:48 AM
Need to translate IPFW rules to IPTABLES rules chris_jon Hosting Security and Technology 1 01-20-2006 05:11 AM
listing iptables rules kapot Hosting Security and Technology 2 12-13-2005 07:41 PM
cleaning iptables rules Lem0nHead Hosting Security and Technology 4 06-07-2004 05:21 PM
Help Setting UP IPtables Rules Huminie Hosting Security and Technology 2 01-11-2004 10:37 PM