LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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 12-05-2021, 03:33 PM   #1
cokiere
LQ Newbie
 
Registered: Jun 2018
Location: Treviso
Distribution: Debian
Posts: 16

Rep: Reputation: Disabled
iprange -dst-range on vpn


hello
i don't understand the difference between option -d and iprange
example:

this works
-A OUTPUT -p udp -m udp -d 103.107.197.0/24 --dport 1194 -j ACCEPT

this doesn't work
-A OUTPUT -p udp -m udp -m iprange --dst-range 37.120.217.84-37.120.217.170 --dport 1194 -j ACCEPT

my iptables:

*mangle
:PREROUTING ACCEPT [0:0]
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
:POSTROUTING ACCEPT [0:0]
COMMIT

*nat
:PREROUTING ACCEPT [0:0]
:INPUT ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
:POSTROUTING ACCEPT [0:0]
COMMIT

# Set a default DROP policy.
*filter
:INPUT DROP [0:0]
:FORWARD DROP [0:0]
:OUTPUT DROP [0:0]

# Allow basic INPUT traffic.
-A INPUT -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT ! -i lo -d 127.0.0.0/8 -j REJECT
-A INPUT -p icmp --icmp-type 8 -m conntrack --ctstate NEW -j ACCEPT

# Allow basic OUTPUT traffic.
-A OUTPUT -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
-A OUTPUT -o lo -j ACCEPT
-A OUTPUT -p icmp -j ACCEPT

# Allow traffic to the OpenVPN server and via the tunnel.
-A OUTPUT -o proton0 -j ACCEPT

-A OUTPUT -p udp -m udp -d 103.107.197.0/24 --dport 1194 -j ACCEPT
-A OUTPUT -p udp -m udp -d 103.107.197.0/24 --dport 5060 -j ACCEPT
-A OUTPUT -p udp -m udp -d 103.107.197.0/24 --dport 9050 -j ACCEPT
-A OUTPUT -p udp -m udp -d 103.107.197.0/24 --dport 4569 -j ACCEPT

# Reject everything else.
-A INPUT -m conntrack --ctstate INVALID -j DROP
-A INPUT -j REJECT --reject-with icmp-port-unreachable
-A FORWARD -j REJECT --reject-with icmp-port-unreachable
-A OUTPUT -j REJECT --reject-with icmp-port-unreachable
COMMIT
 
Old 12-09-2021, 05:46 AM   #2
vincix
Senior Member
 
Registered: Feb 2011
Distribution: Ubuntu, Centos
Posts: 1,240

Rep: Reputation: 103Reputation: 103
I don't know exactly what you mean when you say that the second rule doesn't work (I see that the IPs are different, but I'm guessing you understand that), but the difference is that with with iprange you can give it an arbitrary ip range, regardless of subnetting. So you don't need to specify a network mask, like you do with -d. (with -d not specifying a network mask means only the ip itself, of course).

Last edited by vincix; 12-09-2021 at 05:53 AM.
 
Old 12-09-2021, 06:06 AM   #3
cokiere
LQ Newbie
 
Registered: Jun 2018
Location: Treviso
Distribution: Debian
Posts: 16

Original Poster
Rep: Reputation: Disabled
hi
i wonna set a vpn, as you see. but i'd like to put only the server range:
example:

####server UK
-A OUTPUT -p udp -m udp -m iprange --dst-range 103.107.197.35-103.107.197.127 --dport 1194 -j ACCEPT
i can't get connection with this rule.

only this i can get connection:
##server UK
-A OUTPUT -p udp -m udp -d 103.107.197.0/24 --dport 1194 -j ACCEPT

sure, i have to learn more about iptbles
thanks
 
Old 12-09-2021, 06:15 AM   #4
vincix
Senior Member
 
Registered: Feb 2011
Distribution: Ubuntu, Centos
Posts: 1,240

Rep: Reputation: 103Reputation: 103
So you're setting up these rules on the client side, if I understand correctly?

If yes, then the iprange rule is correct in and of itself. But that's not a perfect overlap. /24 means .1-.254, whereas your iprange rule is restricted to .35-.127. So if your vpn server does not belong to that range, of course it won't work.

Other than that there's no difference between -d and iprange.
 
Old 12-13-2021, 11:58 AM   #5
cokiere
LQ Newbie
 
Registered: Jun 2018
Location: Treviso
Distribution: Debian
Posts: 16

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by vincix View Post
So you're setting up these rules on the client side, if I understand correctly?

If yes, then the iprange rule is correct in and of itself. But that's not a perfect overlap. /24 means .1-.254, whereas your iprange rule is restricted to .35-.127. So if your vpn server does not belong to that range, of course it won't work.

Other than that there's no difference between -d and iprange.
hi
yes, it's a client and yes: the range belongs to the server. i wish to narrow it down.
I need to study more
thanks
 
Old 12-13-2021, 12:50 PM   #6
vincix
Senior Member
 
Registered: Feb 2011
Distribution: Ubuntu, Centos
Posts: 1,240

Rep: Reputation: 103Reputation: 103
Quote:
Originally Posted by cokiere View Post
hi
yes, it's a client and yes: the range belongs to the server. i wish to narrow it down.
I need to study more
thanks
You can create a log rule to port 1194 and see what ip destination it tries.
Code:
iptables -I OUTPUT -p udp -m udp --dport 1194 -j LOG --log-prefix "OVPN: " --log-level 4
And then have a look at /var/log/syslog if you use debian/ubuntu.
If you use centos/alma/rocky/rhel, then add the uncommented line in /etc/rsyslog.conf and check /var/log/kern.
Code:
#kern.*                                                 /dev/console
kern.*                                                 /var/log/kern
 
  


Reply



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
usage of iprange option in ip6tables gopimallikharjun Linux - Newbie 1 03-08-2012 08:56 AM
pktgen: cannot make work the udp port dst range cycling stabul Linux - Networking 1 11-13-2009 08:22 AM
[SOLVED] What are short range link and long range links in routing? mq15 Linux - Networking 6 06-26-2009 11:16 PM
IPTABLES -m iprange --src-range x.x.x.x-y.y.y.y not working mago Slackware 10 12-01-2005 05:36 PM
iptables iprange error MarleyGPN Linux - Networking 5 06-07-2005 09:41 AM

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

All times are GMT -5. The time now is 11:23 AM.

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