nixCraft Linux / UNIX / Shell Scripting Forum

nixCraft

Linux / UNIX Tech Support Forum

ipTables rule to block a port for all internal IP Addresses except one

This is a discussion on ipTables rule to block a port for all internal IP Addresses except one within the Networking, Firewalls and Security forums, part of the Mastering Servers category; I have a Virtual Dedicated Server with 6 IP Addresses. 1 for the server and 5 for other websites. I ...


Register free or login to your account to remove all advertisements.

Go Back   nixCraft Linux / UNIX / Shell Scripting Forum > Mastering Servers > Networking, Firewalls and Security

Linux answers from nixCraft.


Networking, Firewalls and Security No it's not a secret. Talk about firewalls and security issues.

Reply

 

Thread Tools Display Modes
  #1 (permalink)  
Old 8th July 2009, 07:38 AM
Junior Member
 
Join Date: Jul 2009
OS: Debian
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
Rep Power: 0
pranaysharmadelhi is on a distinguished road
Default ipTables rule to block a port for all internal IP Addresses except one

I have a Virtual Dedicated Server with 6 IP Addresses. 1 for the server and 5 for other websites.
I want to block the access to port 9999(control panel) and 22(SSH) for all IP Addresses except 1.
They are internal IP Addresses not external.

So w1.x1.y1.z1:9999 is accessible but
w2.x2.y2.z2:9999
w3.x3.y3.z3:9999
w4.x4.y4.z4:9999
w5.x5.y5.z5:9999
w6.x6.y6.z6:9999
do not work. Please help

I plan to use ipTables to do so since I am using it currently to block ports 993 and 995

Also, I plan to add more IP Addresses later to the same server.
SO I would prefer a rule which would allow access to w1.x1.y1.z1:9999
instead of writing 5 rules to deny access to other IP Addresses, so that I dont have write new rules when I add another IP Address.

Although this is just preference. Any rule works fine for the time being.

Please help.
Reply With Quote
  #2 (permalink)  
Old 8th July 2009, 09:36 AM
nixcraft's Avatar
Never say die
 
Join Date: Jan 2005
Location: BIOS
OS: RHEL
Scripting language: Bash, Perl, Python
Posts: 3,300
Thanks: 13
Thanked 413 Times in 306 Posts
Rep Power: 10
nixcraft has a reputation beyond reputenixcraft has a reputation beyond reputenixcraft has a reputation beyond reputenixcraft has a reputation beyond reputenixcraft has a reputation beyond reputenixcraft has a reputation beyond reputenixcraft has a reputation beyond reputenixcraft has a reputation beyond reputenixcraft has a reputation beyond reputenixcraft has a reputation beyond reputenixcraft has a reputation beyond repute
Default

Replace 1.2.3.4 with your actual IP (add the following to your shell script)
Code:
iptables -A INPUT  -p tcp --destination-port 9999  -d \! 1.2.3.4 -j DROP
iptables -A INPUT  -p tcp --destination-port 22  -d \! 1.2.3.4 -j DROP
service iptables save
Do you have shell script based firewall?
__________________
Vivek Gite
Be proud RHEL user, and let the world know about your enterprise choices! Join RedHat user group.
Do you run a Linux? Let's face it, you need help!
Cricket & IPL News Blog
Reply With Quote
The Following User Says Thank You to nixcraft For This Useful Post:
pranaysharmadelhi (14th July 2009)
  #3 (permalink)  
Old 14th July 2009, 09:49 PM
Junior Member
 
Join Date: Jul 2009
OS: Debian
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
Rep Power: 0
pranaysharmadelhi is on a distinguished road
Default Solved

I used this:
iptables -A INPUT -p TCP -d ! w1.x1.y1.z1 --dport 22 -j REJECT
iptables -A INPUT -p TCP -d ! w1.x1.y1.z1 --dport 9999 -j REJECT
Reply With Quote
Reply

Tags
iptables, iptables block all except one, iptables block port 22, iptables block port 999


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads

Thread Thread Starter Forum Replies Last Post
Iptables block ip address raj Getting started tutorials 2 23rd August 2010 12:11 PM
IPtables MAC & IP rule for internet access Tawfiq Networking, Firewalls and Security 4 2nd August 2009 07:53 AM
How do I block ip's (except some) to access any port? sandeepvreddy Networking, Firewalls and Security 0 14th November 2008 06:26 PM
How can I block yahoo masanger port from 220BX modem. chandra Windows Xp/2000/2003 server administration 3 27th September 2006 11:53 AM
Blocking port in iptables asim.mcp Linux software 3 17th July 2006 10:00 PM


All times are GMT +5.5. The time now is 01:27 PM.


Powered by vBulletin® Version 3.8.6 - Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2
©2005-2010 nixCraft. All rights reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40