Linux - NetworkingThis 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.
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.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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
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.
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
#!/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.
#!/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.
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
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
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.
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
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.