LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 05-02-2017, 04:26 PM   #1
SomethingWitty
LQ Newbie
 
Registered: May 2017
Posts: 3

Rep: Reputation: Disabled
No-Ip dynamic update client blocked by iptables


Dear all,

First of all I am completely new to the world of Linux, so please forgive me any mistakes (or plainly idiotic things).

So the project I am working on is starting a VPN. I am not sure if I will actually use it, but I thought it would be a nice project to start with to teach me something about linux and networking. I had to use the dynamic update client (DUC) from No-ip.com to be able to reach my system. However, the DUC did not update. When flushing my iptables temporarily the DUC did work. Therefor I am assuming it is a problem of my iptables blocking the DUC from reaching the server. I know port 80, 443 and 8245 should be forwared and thus it would be benificial if my iptables would not block these ports. Port 80 and 443 were already accepted, but port 8245 was still blocked. However, even after adding this port to my tables the DUC would still not function. So now I am at a loss. Since flushing my iptables fixed the problem I still think it has to do with my iptables. Currently they look like this.

Quote:

-A INPUT -i lo -j ACCEPT
-A INPUT ! -i lo -s 127.0.0.0/8 -j REJECT
-A OUTPUT -o lo -j ACCEPT


-A INPUT -p icmp -m state --state NEW --icmp-type 8 -j ACCEPT
-A INPUT -p icmp -m state --state ESTABLISHED,RELATED -j ACCEPT
-A OUTPUT -p icmp -j ACCEPT


-A INPUT -i eth0 -p tcp -m state --state NEW,ESTABLISHED --dport 22 -j ACCEPT
-A OUTPUT -o eth0 -p tcp -m state --state ESTABLISHED --sport 22 -j ACCEPT


-A INPUT -i eth0 -p udp -m state --state NEW,ESTABLISHED --dport 1194 -j ACCEPT
-A OUTPUT -o eth0 -p udp -m state --state ESTABLISHED --sport 1194 -j ACCEPT

-A INPUT -i eth0 -p udp -m state --state ESTABLISHED --sport 53 -j ACCEPT
-A OUTPUT -o eth0 -p udp -m state --state NEW,ESTABLISHED --dport 53 -j ACCEPT
-A INPUT -i eth0 -p tcp -m state --state ESTABLISHED --sport 80 -j ACCEPT
-A INPUT -i eth0 -p tcp -m state --state ESTABLISHED --sport 443 -j ACCEPT
-A OUTPUT -o eth0 -p tcp -m state --state NEW,ESTABLISHED --dport 80 -j ACCEPT
-A OUTPUT -o eth0 -p tcp -m state --state NEW,ESTABLISHED --dport 443 -j ACCEPT


-A INPUT -i tun0 -j ACCEPT
-A OUTPUT -o tun0 -j ACCEPT


-A INPUT -i eth0 -p tcp -m state --state ESTABLISHED --sport 8245 -j ACCEPT
-A OUTPUT -o eth0 -p tcp -m state --state NEW,ESTABLISHED --dport 8245 -j ACCEPT


-A INPUT -m limit --limit 3/min -j LOG --log-prefix "iptables_INPUT_denied: " --log-level 4
-A FORWARD -m limit --limit 3/min -j LOG --log-prefix "iptables_FORWARD_denied: " --log-level 4
-A OUTPUT -m limit --limit 3/min -j LOG --log-prefix "iptables_OUTPUT_denied: " --log-level 4


-A INPUT -j REJECT
-A FORWARD -j REJECT
-A OUTPUT -j REJECT
I admit this is largely based on what I read on the internet, but for my amateur eye it looked like a coherent set. But I am at a loss why the DUC is being blocked and hope you guys might have some advice for me.

Thanks for your help and time in advance,
 
Old 05-02-2017, 07:09 PM   #2
Pearlseattle
Member
 
Registered: Aug 2007
Location: Zurich, Switzerland
Distribution: Gentoo
Posts: 999

Rep: Reputation: 141Reputation: 141
Hi

I don't know much about FW, but still, here are my recommendations:

1)
Don't put everything inside a single monolithic bloc - split it up, as it's easier to handle.
E.g. the "main" script that you would call could look like this:
Code:
#!/bin/bash

#The bridge
export LAN=br0
#The network interface that connects to the outside world
export WAN=br0
#The internal NIC
export INT=lo
#Path where I saved all the files
MYPATH="/opt/myscripts/firewall"

#START

#Reset everything
iptables --flush
iptables --delete-chain

#Set up the default behaviours for when no rule explicitly blocks or allows something
iptables -P INPUT DROP
iptables -P OUTPUT DROP
iptables -P FORWARD DROP

#Let everything to the loopback interface
iptables -A INPUT -i lo -j ACCEPT
iptables -A OUTPUT -o lo -j ACCEPT
#Now a "ping localhost" should work

"$MYPATH"/iptables-start-1input.sh
"$MYPATH"/iptables-start-2output.sh
"$MYPATH"/iptables-start-3forward.sh
"$MYPATH"/iptables-start-4logging.sh
2)
Put at the very end the stuff that logs everything which you don't explicitly allow nor deny in the other scripts, which in this example would be the contents of "iptables-start-4logging.sh", which could look like this:
Code:
#!/bin/bash

#Max log label string length is "xxxxxxxxxxxxxxxxxxxxxxxxxxx"
iptables -A INPUT -j LOG --log-prefix "Def inbound rejection: "
iptables -A OUTPUT -j LOG --log-prefix "Def outbound rejection: "
iptables -A FORWARD -j LOG --log-prefix "Def forwarding rejection: "
This might seem at first unrelated to your question, but indirectly, by implementing a log for "anything unexpected" you'll always immediately be able to identify anything that blocks the traffic that you actually want to go through.


Btw. pls. keep in mind that as much as I know, "the future" of Linux firewall is "nftables" (using it since a while and it's not bad, but most of the software still has to catch up).
 
Old 05-02-2017, 09:28 PM   #3
frankbell
LQ Guru
 
Registered: Jan 2006
Location: Virginia, USA
Distribution: Slackware, Ubuntu MATE, Mageia, and whatever VMs I happen to be playing with
Posts: 19,096
Blog Entries: 28

Rep: Reputation: 6088Reputation: 6088Reputation: 6088Reputation: 6088Reputation: 6088Reputation: 6088Reputation: 6088Reputation: 6088Reputation: 6088Reputation: 6088Reputation: 6088
Per the noip docs, have you opened ports 80, 443, and 8245?
 
Old 05-06-2017, 04:09 PM   #4
SomethingWitty
LQ Newbie
 
Registered: May 2017
Posts: 3

Original Poster
Rep: Reputation: Disabled
Sorry for the late reply.

Quote:
Originally Posted by Pearlseattle View Post
Hi

I don't know much about FW, but still, here are my recommendations:

1)
Don't put everything inside a single monolithic bloc - split it up, as it's easier to handle.
E.g. the "main" script that you would call could look like this:
Code:
#!/bin/bash

#The bridge
export LAN=br0
#The network interface that connects to the outside world
export WAN=br0
#The internal NIC
export INT=lo
#Path where I saved all the files
MYPATH="/opt/myscripts/firewall"

#START

#Reset everything
iptables --flush
iptables --delete-chain

#Set up the default behaviours for when no rule explicitly blocks or allows something
iptables -P INPUT DROP
iptables -P OUTPUT DROP
iptables -P FORWARD DROP

#Let everything to the loopback interface
iptables -A INPUT -i lo -j ACCEPT
iptables -A OUTPUT -o lo -j ACCEPT
#Now a "ping localhost" should work

"$MYPATH"/iptables-start-1input.sh
"$MYPATH"/iptables-start-2output.sh
"$MYPATH"/iptables-start-3forward.sh
"$MYPATH"/iptables-start-4logging.sh
2)
Put at the very end the stuff that logs everything which you don't explicitly allow nor deny in the other scripts, which in this example would be the contents of "iptables-start-4logging.sh", which could look like this:
Code:
#!/bin/bash

#Max log label string length is "xxxxxxxxxxxxxxxxxxxxxxxxxxx"
iptables -A INPUT -j LOG --log-prefix "Def inbound rejection: "
iptables -A OUTPUT -j LOG --log-prefix "Def outbound rejection: "
iptables -A FORWARD -j LOG --log-prefix "Def forwarding rejection: "
This might seem at first unrelated to your question, but indirectly, by implementing a log for "anything unexpected" you'll always immediately be able to identify anything that blocks the traffic that you actually want to go through.


Btw. pls. keep in mind that as much as I know, "the future" of Linux firewall is "nftables" (using it since a while and it's not bad, but most of the software still has to catch up).
Thank you for your reply. I did not know about nftables, I will look into it. Thanks for the advice. The rest of your suggestions I can hopefully implement soon. It has been a bit busy recently.

Quote:
Originally Posted by frankbell View Post
Per the noip docs, have you opened ports 80, 443, and 8245?
Thanks for your reply. As per my basic knowledge I think those ports should be openend in iptables by their specific rules. If I am correct these rules should fix that, right?

Quote:
-A INPUT -i eth0 -p tcp -m state --state ESTABLISHED --sport 80 -j ACCEPT
-A INPUT -i eth0 -p tcp -m state --state ESTABLISHED --sport 443 -j ACCEPT
-A OUTPUT -o eth0 -p tcp -m state --state NEW,ESTABLISHED --dport 80 -j ACCEPT
-A OUTPUT -o eth0 -p tcp -m state --state NEW,ESTABLISHED --dport 443 -j ACCEPT

-A INPUT -i eth0 -p tcp -m state --state ESTABLISHED --sport 8245 -j ACCEPT
-A OUTPUT -o eth0 -p tcp -m state --state NEW,ESTABLISHED --dport 8245 -j ACCEPT

Regards
 
Old 05-07-2017, 04:15 PM   #5
lazydog
Senior Member
 
Registered: Dec 2003
Location: The Key Stone State
Distribution: CentOS Sabayon and now Gentoo
Posts: 1,249
Blog Entries: 3

Rep: Reputation: 194Reputation: 194
Your firewall rules and how they need to be setup are going to depend on how your network is deployed now.

Is the VPN and the web site on the same system? If so then you are going to need INPUT rules for your tun0 interface. If the web site is on another computer then you are going to need FORWARD rules for your tun0 interface.

I am thinking that your VPN and the web site are on the same computer as you have stated if you remove the firewall it all works.

So I cleaned up your rules for you. I agree that you should group your rules together as it makes it easier to find what you are looking for.

Code:
-A INPUT -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -p icmp -m conntrack --ctstate --icmp-type 8 -j ACCEPT
-A INPUT -i eth0 -p tcp -m conntrack --ctstate NEW --dport 22 -j ACCEPT
-A INPUT -i eth0 -p udp -m conntrack --ctstate NEW --dport 1194 -j ACCEPT


# If your tun0 and web server are on the same system then you need the following rules
#
-A INPUT -i tun0 -p udp -m conntrack --ctstate NEW -m multiport --dport 80,443,8245 -j ACCEPT


-A INPUT -m limit --limit 3/min -j LOG --log-prefix "iptables_INPUT_denied: " --log-level 4
-A INPUT -j REJECT


# These rules are not required as the first rule will allow all ESTABLISHED and RELATED connection through
#
#-A INPUT -i eth0 -p tcp -m state --state NEW,ESTABLISHED --dport 22 -j ACCEPT
#-A INPUT -i eth0 -p udp -m state --state NEW,ESTABLISHED --dport 1194 -j ACCEPT
#-A INPUT -i eth0 -p udp -m state --state ESTABLISHED --sport 53 -j ACCEPT
#-A INPUT -i eth0 -p tcp -m state --state ESTABLISHED --sport 80 -j ACCEPT
#-A INPUT -i eth0 -p tcp -m state --state ESTABLISHED --sport 443 -j ACCEPT
#-A INPUT -i tun0 -j ACCEPT
#-A INPUT -i eth0 -p tcp -m state --state ESTABLISHED --sport 8245 -j ACCEPT


-A OUTPUT -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
-A OUTPUT -o lo -j ACCEPT
-A OUTPUT -p icmp -j ACCEPT
-A OUTPUT -o eth0 -p udp -m conntrack --ctstate NEW --dport 53 -j ACCEPT
-A OUTPUT -o eth0 -p tcp -m conntrack --ctstate NEW --dport 80 -j ACCEPT
-A OUTPUT -o eth0 -p tcp -m conntrack --ctstate NEW --dport 443 -j ACCEPT
-A OUTPUT -o eth0 -p tcp -m conntrack --ctstate NEW --dport 8245 -j ACCEPT
-A OUTPUT -o tun0 -m conntrack --ctstate NEW -j ACCEPT
-A OUTPUT -m limit --limit 3/min -j LOG --log-prefix "iptables_OUTPUT_denied: " --log-level 4
-A OUTPUT -j REJECT


# These rules are not required as the first rule will allow all ESTABLISHED and RELATED connection through
#
#-A OUTPUT -o eth0 -p tcp -m state --state ESTABLISHED --sport 22 -j ACCEPT
#-A OUTPUT -o eth0 -p udp -m state --state ESTABLISHED --sport 1194 -j ACCEPT
#-A OUTPUT -o eth0 -p udp -m state --state NEW,ESTABLISHED --dport 53 -j ACCEPT
#-A OUTPUT -o eth0 -p tcp -m state --state NEW,ESTABLISHED --dport 80 -j ACCEPT
#-A OUTPUT -o eth0 -p tcp -m state --state NEW,ESTABLISHED --dport 443 -j ACCEPT
#-A OUTPUT -o tun0 -j ACCEPT
#-A OUTPUT -o eth0 -p tcp -m state --state NEW,ESTABLISHED --dport 8245 -j ACCEPT


-A OUTPUT -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
-A FORWARD -m limit --limit 3/min -j LOG --log-prefix "iptables_FORWARD_denied: " --log-level 4
-A FORWARD -j REJECT
Normally I don't place anything in the OUTPUT chain as I normally trust everything leaving my system so the OUTPUT rule could be as simple as
Code:
-A OUTPUT -m conntrack --ctstate NEW,RELATED,ESTABLISHED -j ACCEPT
and the rest of the rules could be removed.

If in fact your web server and your VPN are on different machines then change
Code:
-A INPUT -i tun0 -p udp -m conntrack --ctstate NEW -m multiport --dport 80,443,8245 -j ACCEPT
to
Code:
-A FORWARD -i tun0 -p udp -m conntrack --ctstate NEW -m multiport --dport 80,443,8245 -j ACCEPT
As to nftables or firewealld, I do not see them taking over anytime soon even though big brother, RedHat, is pushing firewalld down their users throats.

While I have not looking into it I believe that nftables, like firewalld, is a front end for iptables. If you compare the output from firewalld you will see it uses iptables setup with the exception that firewalld creates many more tables then what is necessary making things more complicated.
 
Old 05-10-2017, 04:40 PM   #6
SomethingWitty
LQ Newbie
 
Registered: May 2017
Posts: 3

Original Poster
Rep: Reputation: Disabled
Thanks lazydog for the help!

Indeed, both are indeed running from the same machine (raspberry pi by the way, in case this is relevant). The way you cleaned up the rules seems much better. Trusting your own output makes sense, now you mention it :-)
My apologies for not posting my own cleaned rules yet. I was quite busy lately and could not find the time to properly sit down and sort things out. I am not at the level yet to do it quickly and did not want to bother your time with a half finished product.
The guides I was following to learn something about iptables were appearently a bit out-dated, since they did not mention the conntrack or the ctstate functions. I am quite busy with work at the moment, but I will try to find some time this weekend to study conntrack, ctstate and to continue the work on the VPN.

Regards!
 
Old 05-10-2017, 07:29 PM   #7
lazydog
Senior Member
 
Registered: Dec 2003
Location: The Key Stone State
Distribution: CentOS Sabayon and now Gentoo
Posts: 1,249
Blog Entries: 3

Rep: Reputation: 194Reputation: 194
Quote:
Originally Posted by SomethingWitty View Post
Thanks lazydog for the help!
Glad I could help.

Quote:
My apologies for not posting my own cleaned rules yet. I was quite busy lately and could not find the time to properly sit down and sort things out. I am not at the level yet to do it quickly and did not want to bother your time with a half finished product.
No apologies necessary. Life will always find a way to get in the way.

Quote:
The guides I was following to learn something about iptables were appearently a bit out-dated, since they did not mention the conntrack or the ctstate functions. I am quite busy with work at the moment, but I will try to find some time this weekend to study conntrack, ctstate and to continue the work on the VPN.
Yeah, I don't think there is much out there in a way of an up-2-date tutorial. I learned a lot about building firewall following this IPTABLES TUTORIAL. It too is out of date but a lot of what is in there is still relevant and what is missing can be found in the man pages
 
  


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
allowing dyndns client - update iptables frequently? jeff_k Linux - Security 3 09-12-2010 07:50 PM
[SOLVED] HTTP Access Blocked After iptables Update IceBurn Linux - Security 9 11-05-2009 03:59 PM
No-IP dynamic update client - Linux Version 1kyle SUSE / openSUSE 3 09-27-2008 12:37 PM
trying to install dynamic update client for no-ip Matt.M Linux - Software 1 07-14-2007 07:29 PM
dynamic update client nasirjones Linux - Newbie 1 01-14-2005 11:12 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 04:56 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