Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game. |
| Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
|
01-14-2011, 03:10 PM
|
#1
|
|
LQ Newbie
Registered: Jun 2010
Posts: 25
Rep:
|
IPTABLES help
Im working on my minecraft server so that with the exception of outgoing web acess, incoming minecraft server acess, and incoming ssh, all other ports and services are blocked. This is on the inside of my router. Unfortunately while the ssh works, web acees and the minecraft protocol don't. here is the script im using.
#!/bin/sh
SERVER_IP=192.168.1.95
# Flushing all rules
iptables -F
iptables -X
# Setting default filter policy
iptables -P INPUT DROP
iptables -P OUTPUT DROP
iptables -P FORWARD DROP
# Allow unlimited traffic on loopback
iptables -A INPUT -i lo -j ACCEPT
iptables -A OUTPUT -o lo -j ACCEPT
#allow http
sudo iptables -A INPUT -p udp -m udp --sport 53 -j ACCEPT
sudo iptables -A INPUT -p tcp -m tcp --sport 80 -j ACCEPT
#allow inbound
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
# Allow incoming ssh only
iptables -A INPUT -p tcp -s 0/0 -d $SERVER_IP --sport 513:65535 --dport 22 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -p tcp -s $SERVER_IP -d 0/0 --sport 22 --dport 513:65535 -m state --state ESTABLISHED -j ACCEPT
#allow minecraft
iptables -A INPUT -p tcp --dport 25565 -j ACCEPT
iptables -A OUTPUT -p tcp --dport 25565 -j ACCEPT
# make sure nothing comes or goes out of this box
iptables -A INPUT -j DROP
iptables -A OUTPUT -j DROP
|
|
|
|
01-14-2011, 03:28 PM
|
#2
|
|
Member
Registered: Mar 2008
Posts: 155
Rep:
|
It looks like you don't have any rule to allow output for web traffic. Does minecraft actually use the same port for outgoing as incoming? I'm not familiar with the protocol, but most tcp protocols don't.
You can add the following lines before the DROP lines for troubleshooting:
Code:
iptables -A INPUT -j LOG --log-prefix "input drop "
iptables -A OUTPUT -j LOG --log-prefix "output drop "
Then your log files will show you where it's getting stopped.
|
|
|
|
01-14-2011, 05:29 PM
|
#3
|
|
LQ Newbie
Registered: Jun 2010
Posts: 25
Original Poster
Rep:
|
Quote:
Originally Posted by tsg
It looks like you don't have any rule to allow output for web traffic. Does minecraft actually use the same port for outgoing as incoming? I'm not familiar with the protocol, but most tcp protocols don't.
You can add the following lines before the DROP lines for troubleshooting:
Code:
iptables -A INPUT -j LOG --log-prefix "input drop "
iptables -A OUTPUT -j LOG --log-prefix "output drop "
Then your log files will show you where it's getting stopped.
|
Does the area with the #http comment not allow web traffic? Networking is a new thing for me..... haha
|
|
|
|
01-14-2011, 09:05 PM
|
#4
|
|
Moderator
Registered: May 2001
Posts: 24,805
|
Code:
#!/bin/sh --
# Flush all rules
iptables -F; iptables -X
# Setting default filter policy
iptables -P INPUT DROP; iptables -P FORWARD DROP; iptables -P OUTPUT ACCEPT
# Allow unlimited traffic on loopback
iptables -A INPUT -i lo -j ACCEPT; iptables -A OUTPUT -o lo -j ACCEPT
# Allow inbound existing connections first as this is the majority of traffic
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
# Allow SSH and Minecraft as example in one rule
iptables -A INPUT -m state --state NEW -m tcp -p tcp -m multiport --dports 22,25565 -j ACCEPT
iptables -A INPUT -p udp -m state --state NEW -m tcp --dport 25565 -j ACCEPT
# Allow HTTP but as example flood-limit access to max 30 requests per minute
iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -m limit --limit 10/minute --limit-burst 30 -j ACCEPT
# Drop ICMP frags but allow some ICMP diagnostic messages:
iptables -A INPUT -p icmp --fragment -j DROP
for ICMPTYPE in echo-reply time-exceeded fragmentation-needed; do
iptables -A INPUT -p icmp --icmp-type ${ICMPTYPE} -j ACCEPT; done
# Just in case catchall rule to reject anything else (should not occur):
iptables -A INPUT -j REJECT --reject-with icmp-host-prohibited
# End
exit 0
- Unless your server gets compromised outbound traffic can be new connections like DNS resolution, accessing a web page or getting remote email and established ones like your Minecraft server responding to connected players. So while completely locking down the machine is commendable it is not the primary security concern and I set your outbound policy to ACCEPT which you may or may not like.
- Unless you host your own Domain Name Service your only inbound DNS traffic will be of state "ESTABLISHED" so the port 53 rule is gone.
- I'm not certain Minecraft doesn't need UDP so I added that.
- ICMP is used to check connection problems so you should allow some of it.
- Some network ranges should not be allowed in. They're called "bogons" which you will find here: http://www.team-cymru.org/Services/B...gon-bn-agg.txt
- There are more states that iptables recognizes like INVALID you can filter. See the standard work on iptables for more information: http://www.frozentux.net/iptables-tu...tml/index.html
- For running SSH 0) do deny root logins in /etc/sshd_config, 1) use an unprivileged account to login with pubkey auth and only *then* use sudo and 2) install fail2ban.
- At a later point you might find your connection saturated: you might want to read up on rate-limiting traffic and bandwidth shaping.
- Install Logwatch and read those reports.
* And please harden your machine properly before exposing it to the 'net.
|
|
|
|
01-14-2011, 09:43 PM
|
#5
|
|
LQ Newbie
Registered: Jun 2010
Posts: 25
Original Poster
Rep:
|
Quote:
Originally Posted by unSpawn
Code:
#!/bin/sh --
# Flush all rules
iptables -F; iptables -X
# Setting default filter policy
iptables -P INPUT DROP; iptables -P FORWARD DROP; iptables -P OUTPUT ACCEPT
# Allow unlimited traffic on loopback
iptables -A INPUT -i lo -j ACCEPT; iptables -A OUTPUT -o lo -j ACCEPT
# Allow inbound existing connections first as this is the majority of traffic
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
# Allow SSH and Minecraft as example in one rule
iptables -A INPUT -m state --state NEW -m tcp -p tcp -m multiport --dports 22,25565 -j ACCEPT
iptables -A INPUT -p udp -m state --state NEW -m tcp --dport 25565 -j ACCEPT
# Allow HTTP but as example flood-limit access to max 30 requests per minute
iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -m limit --limit 10/minute --limit-burst 30 -j ACCEPT
# Drop ICMP frags but allow some ICMP diagnostic messages:
iptables -A INPUT -p icmp --fragment -j DROP
for ICMPTYPE in echo-reply time-exceeded fragmentation-needed; do
iptables -A INPUT -p icmp --icmp-type ${ICMPTYPE} -j ACCEPT; done
# Just in case catchall rule to reject anything else (should not occur):
iptables -A INPUT -j REJECT --reject-with icmp-host-prohibited
# End
exit 0
- Unless your server gets compromised outbound traffic can be new connections like DNS resolution, accessing a web page or getting remote email and established ones like your Minecraft server responding to connected players. So while completely locking down the machine is commendable it is not the primary security concern and I set your outbound policy to ACCEPT which you may or may not like.
- Unless you host your own Domain Name Service your only inbound DNS traffic will be of state "ESTABLISHED" so the port 53 rule is gone.
- I'm not certain Minecraft doesn't need UDP so I added that.
- ICMP is used to check connection problems so you should allow some of it.
- Some network ranges should not be allowed in. They're called "bogons" which you will find here: http://www.team-cymru.org/Services/B...gon-bn-agg.txt
- There are more states that iptables recognizes like INVALID you can filter. See the standard work on iptables for more information: http://www.frozentux.net/iptables-tu...tml/index.html
- For running SSH 0) do deny root logins in /etc/sshd_config, 1) use an unprivileged account to login with pubkey auth and only *then* use sudo and 2) install fail2ban.
- At a later point you might find your connection saturated: you might want to read up on rate-limiting traffic and bandwidth shaping.
- Install Logwatch and read those reports.
* And please harden your machine properly before exposing it to the 'net.
|
Thanks so much. Im going to try this configuration out right now. Ill keep you posted.
|
|
|
|
01-15-2011, 12:15 PM
|
#6
|
|
LQ Newbie
Registered: Jun 2010
Posts: 25
Original Poster
Rep:
|
Quote:
Originally Posted by stratosmacker
Thanks so much. Im going to try this configuration out right now. Ill keep you posted.
|
I tried the config, as soon as i tried to set the file with the config as the source eg source /etc......./firewallconfig
it booted me out of su -. It shot some error i think but i couldnt read it
|
|
|
|
01-15-2011, 04:04 PM
|
#7
|
|
LQ Newbie
Registered: Jun 2010
Posts: 25
Original Poster
Rep:
|
also now im locked out even with ssh. Im going to go to the physical source.
|
|
|
|
01-15-2011, 07:09 PM
|
#8
|
|
Moderator
Registered: May 2001
Posts: 24,805
|
I'm sorry to hear that, this should not have happened.
|
|
|
|
01-16-2011, 10:03 AM
|
#9
|
|
LQ Newbie
Registered: Jun 2010
Posts: 25
Original Poster
Rep:
|
Its fine. I appreciate the insight either way. If you do happen to realize whats wrong though feel free to pipe up. In the mean time im going to try a few things
|
|
|
|
01-17-2011, 08:31 AM
|
#10
|
|
Member
Registered: Mar 2008
Posts: 155
Rep:
|
On this line:
Code:
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
you have to specify "-p tcp" or it won't accept the --state parameters.
To answer your earlier question:
Quote:
|
Does the area with the #http comment not allow web traffic? Networking is a new thing for me..... haha
|
You've allowed incoming traffic, but not outgoing. In practice, most firewalls usually allow any outgoing traffic on an established connection, so specifying the port number isn't required like you've done for ssh and minecraft.
|
|
|
|
01-17-2011, 03:09 PM
|
#11
|
|
LQ Newbie
Registered: Jun 2010
Posts: 25
Original Poster
Rep:
|
Quote:
Originally Posted by tsg
On this line:
Code:
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
you have to specify "-p tcp" or it won't accept the --state parameters.
To answer your earlier question:
You've allowed incoming traffic, but not outgoing. In practice, most firewalls usually allow any outgoing traffic on an established connection, so specifying the port number isn't required like you've done for ssh and minecraft.
|
I changed the line to:
iptables -p tcp -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
but it still kicks me out of su - when I point to it as the source
|
|
|
|
01-17-2011, 04:38 PM
|
#12
|
|
Moderator
Registered: May 2001
Posts: 24,805
|
Quote:
Originally Posted by tsg
you have to specify "-p tcp" or it won't accept the --state parameters.
|
Does it now? If it does then how come I haven't got any problems:
Code:
~]# /sbin/iptables -t filter -n -v -x --line-numbers -L INPUT|grep EST
1 98287665 43703590608 ACCEPT all -- * * 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED
(and no, there's no "-p" rules feeding into the INPUT chain).
|
|
|
|
01-17-2011, 04:39 PM
|
#13
|
|
Moderator
Registered: May 2001
Posts: 24,805
|
Quote:
Originally Posted by stratosmacker
I changed the line (..) but it still kicks me out of su - when I point to it as the source
|
If and when you get back in check your syslog log files for clues? Right now I'm not having any.
|
|
|
|
01-18-2011, 09:03 AM
|
#14
|
|
Member
Registered: Mar 2008
Posts: 155
Rep:
|
Quote:
Originally Posted by unSpawn
Does it now? If it does then how come I haven't got any problems:
|
My bad. That must have been an ipchains requirement.
|
|
|
|
01-19-2011, 06:11 PM
|
#15
|
|
LQ Newbie
Registered: Jun 2010
Posts: 25
Original Poster
Rep:
|
Quote:
Originally Posted by unSpawn
Does it now? If it does then how come I haven't got any problems:
Code:
~]# /sbin/iptables -t filter -n -v -x --line-numbers -L INPUT|grep EST
1 98287665 43703590608 ACCEPT all -- * * 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED
(and no, there's no "-p" rules feeding into the INPUT chain).
|
where exactly do I pass the rules then? IPTABLES is a fun cookie.
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 11:55 AM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|