How to filter ranges of IP addresses?
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
How could I filter a single IP address or a range of IP addresses to prevent them from accessing my computer?
Examples:
Block
31.13.76.102
Block from
216.58.192.0
to216.58.223.255
Block from
173.194.0.0
to173.194.255.255
Block from
74.125.136.0
to74.125.136.255
I would like to block them from accessing my computer without additionnal conditions.
I know that one can use iptables
in this situation, but I am unaware of the exact syntax, how to make the changes permanent, and which command to run in order to launch the iptables
service at startup. I also don't want to make mistakes that may break my access to the Internet.
linux networking iptables filter ip-address
add a comment |Â
up vote
0
down vote
favorite
How could I filter a single IP address or a range of IP addresses to prevent them from accessing my computer?
Examples:
Block
31.13.76.102
Block from
216.58.192.0
to216.58.223.255
Block from
173.194.0.0
to173.194.255.255
Block from
74.125.136.0
to74.125.136.255
I would like to block them from accessing my computer without additionnal conditions.
I know that one can use iptables
in this situation, but I am unaware of the exact syntax, how to make the changes permanent, and which command to run in order to launch the iptables
service at startup. I also don't want to make mistakes that may break my access to the Internet.
linux networking iptables filter ip-address
OK for filtering rules. Thank you for all the repliers. Now does someone know which addresses range to target for getting rid of advertisements on spotifi free accounts ? Thank you everyone.
â Thierry
Mar 6 at 0:33
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
How could I filter a single IP address or a range of IP addresses to prevent them from accessing my computer?
Examples:
Block
31.13.76.102
Block from
216.58.192.0
to216.58.223.255
Block from
173.194.0.0
to173.194.255.255
Block from
74.125.136.0
to74.125.136.255
I would like to block them from accessing my computer without additionnal conditions.
I know that one can use iptables
in this situation, but I am unaware of the exact syntax, how to make the changes permanent, and which command to run in order to launch the iptables
service at startup. I also don't want to make mistakes that may break my access to the Internet.
linux networking iptables filter ip-address
How could I filter a single IP address or a range of IP addresses to prevent them from accessing my computer?
Examples:
Block
31.13.76.102
Block from
216.58.192.0
to216.58.223.255
Block from
173.194.0.0
to173.194.255.255
Block from
74.125.136.0
to74.125.136.255
I would like to block them from accessing my computer without additionnal conditions.
I know that one can use iptables
in this situation, but I am unaware of the exact syntax, how to make the changes permanent, and which command to run in order to launch the iptables
service at startup. I also don't want to make mistakes that may break my access to the Internet.
linux networking iptables filter ip-address
edited Mar 5 at 18:36
aliceinpalth
760116
760116
asked Mar 5 at 17:50
Thierry
11
11
OK for filtering rules. Thank you for all the repliers. Now does someone know which addresses range to target for getting rid of advertisements on spotifi free accounts ? Thank you everyone.
â Thierry
Mar 6 at 0:33
add a comment |Â
OK for filtering rules. Thank you for all the repliers. Now does someone know which addresses range to target for getting rid of advertisements on spotifi free accounts ? Thank you everyone.
â Thierry
Mar 6 at 0:33
OK for filtering rules. Thank you for all the repliers. Now does someone know which addresses range to target for getting rid of advertisements on spotifi free accounts ? Thank you everyone.
â Thierry
Mar 6 at 0:33
OK for filtering rules. Thank you for all the repliers. Now does someone know which addresses range to target for getting rid of advertisements on spotifi free accounts ? Thank you everyone.
â Thierry
Mar 6 at 0:33
add a comment |Â
3 Answers
3
active
oldest
votes
up vote
3
down vote
While you could use /etc/hosts.deny
, hosts.deny only works with TCP wrapped applications such as ssh or xinetd. I would recommend using iptables
since it is a true firewall to your system. Just use something like this:
iptables -I INPUT -s 31.13.76.102 -j DROP
iptables -I INPUT -m iprange --src-range 216.58.192.0-216.58.223.255 -j DROP
iptables -I INPUT -m iprange --src-range 173.194.0.0-173.194.255.255 -j DROP
iptables -I INPUT -m iprange --src-range 74.125.136.0-74.125.136.255 -j DROP
iptables-save > /etc/sysconfig/iptables
The iprange
is a really cool module to use for situations such as this.
Thank you for your answer Jaken551. Three more questions please : #0 Should I start Iptables on my system before typing the filtering rules, if yes how ? #1 What is the command to start iptables at each boot (I run Majaro, an Arch-Linux based distribution whose init system is systemd) ? #2 There is no /etc/sysconfig directory on my defaukt configuration, which command do I have to type to make the filtration rules permanent ?
â Thierry
Mar 5 at 19:41
#0: You can edit theiptables
rules whether or not the service is running, starting it is up to you. #1: Runsystemctl enable iptables
in order to have iptables service start at boot. #2: For Arch-Linux theiptables
config file is/etc/iptables/iptables.rules
. Unfortunately, this is not created by default with Arch, but running theiptables-save /etc/iptables/iptables.rules
will create it for you :) Best of luck to you!
â Jaken551
Mar 5 at 21:30
Thank you for your answer Jaken551. It does filter the targets BUT ranges seem far too large and block part of interesting targets wheraes I only want to target advertisements...
â Thierry
Mar 6 at 0:27
What exactly are you trying to block? This is only blocking incoming connections. If you are trying to block advertisements, firewall rules are not really what you want.
â Jaken551
Mar 6 at 7:11
Yes, I want to block spotifi ad-server to get rid of commercials on the free account through the spotify application.. The problem is finding a reliable list of addresses to block. I found the mentionned-above one on reddit, but its seems to be far too obstructing. Searching with 'spotify' ad-servers' list' on Internet didnt return anything up-to-date and reliable so far for me. If you have any info, you are welcome. Some are mentionned on github but its not perfect... Maybe its possible to find it using tools like wireshark but I dont know enough to use it properly. Thank you again.
â Thierry
Mar 6 at 7:34
 |Â
show 1 more comment
up vote
0
down vote
Simply add the following to /etc/hosts.deny
:
ALL: 31.13.76.102
ALL: 216.58.192.0/19
ALL: 173.194.0.0/16
ALL: 74.125.136.0/24
add a comment |Â
up vote
0
down vote
The ufw
command (Uncomplicated FireWall, a simplified front-end for iptables, initially for Ubuntu, now also available for Debian and other distros) accepts CIDR range specifications, for instance:
ufw insert 1 deny from 31.13.76.102 # single address
ufw insert 1 deny from 216.58.192.0/18 # range
add a comment |Â
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
While you could use /etc/hosts.deny
, hosts.deny only works with TCP wrapped applications such as ssh or xinetd. I would recommend using iptables
since it is a true firewall to your system. Just use something like this:
iptables -I INPUT -s 31.13.76.102 -j DROP
iptables -I INPUT -m iprange --src-range 216.58.192.0-216.58.223.255 -j DROP
iptables -I INPUT -m iprange --src-range 173.194.0.0-173.194.255.255 -j DROP
iptables -I INPUT -m iprange --src-range 74.125.136.0-74.125.136.255 -j DROP
iptables-save > /etc/sysconfig/iptables
The iprange
is a really cool module to use for situations such as this.
Thank you for your answer Jaken551. Three more questions please : #0 Should I start Iptables on my system before typing the filtering rules, if yes how ? #1 What is the command to start iptables at each boot (I run Majaro, an Arch-Linux based distribution whose init system is systemd) ? #2 There is no /etc/sysconfig directory on my defaukt configuration, which command do I have to type to make the filtration rules permanent ?
â Thierry
Mar 5 at 19:41
#0: You can edit theiptables
rules whether or not the service is running, starting it is up to you. #1: Runsystemctl enable iptables
in order to have iptables service start at boot. #2: For Arch-Linux theiptables
config file is/etc/iptables/iptables.rules
. Unfortunately, this is not created by default with Arch, but running theiptables-save /etc/iptables/iptables.rules
will create it for you :) Best of luck to you!
â Jaken551
Mar 5 at 21:30
Thank you for your answer Jaken551. It does filter the targets BUT ranges seem far too large and block part of interesting targets wheraes I only want to target advertisements...
â Thierry
Mar 6 at 0:27
What exactly are you trying to block? This is only blocking incoming connections. If you are trying to block advertisements, firewall rules are not really what you want.
â Jaken551
Mar 6 at 7:11
Yes, I want to block spotifi ad-server to get rid of commercials on the free account through the spotify application.. The problem is finding a reliable list of addresses to block. I found the mentionned-above one on reddit, but its seems to be far too obstructing. Searching with 'spotify' ad-servers' list' on Internet didnt return anything up-to-date and reliable so far for me. If you have any info, you are welcome. Some are mentionned on github but its not perfect... Maybe its possible to find it using tools like wireshark but I dont know enough to use it properly. Thank you again.
â Thierry
Mar 6 at 7:34
 |Â
show 1 more comment
up vote
3
down vote
While you could use /etc/hosts.deny
, hosts.deny only works with TCP wrapped applications such as ssh or xinetd. I would recommend using iptables
since it is a true firewall to your system. Just use something like this:
iptables -I INPUT -s 31.13.76.102 -j DROP
iptables -I INPUT -m iprange --src-range 216.58.192.0-216.58.223.255 -j DROP
iptables -I INPUT -m iprange --src-range 173.194.0.0-173.194.255.255 -j DROP
iptables -I INPUT -m iprange --src-range 74.125.136.0-74.125.136.255 -j DROP
iptables-save > /etc/sysconfig/iptables
The iprange
is a really cool module to use for situations such as this.
Thank you for your answer Jaken551. Three more questions please : #0 Should I start Iptables on my system before typing the filtering rules, if yes how ? #1 What is the command to start iptables at each boot (I run Majaro, an Arch-Linux based distribution whose init system is systemd) ? #2 There is no /etc/sysconfig directory on my defaukt configuration, which command do I have to type to make the filtration rules permanent ?
â Thierry
Mar 5 at 19:41
#0: You can edit theiptables
rules whether or not the service is running, starting it is up to you. #1: Runsystemctl enable iptables
in order to have iptables service start at boot. #2: For Arch-Linux theiptables
config file is/etc/iptables/iptables.rules
. Unfortunately, this is not created by default with Arch, but running theiptables-save /etc/iptables/iptables.rules
will create it for you :) Best of luck to you!
â Jaken551
Mar 5 at 21:30
Thank you for your answer Jaken551. It does filter the targets BUT ranges seem far too large and block part of interesting targets wheraes I only want to target advertisements...
â Thierry
Mar 6 at 0:27
What exactly are you trying to block? This is only blocking incoming connections. If you are trying to block advertisements, firewall rules are not really what you want.
â Jaken551
Mar 6 at 7:11
Yes, I want to block spotifi ad-server to get rid of commercials on the free account through the spotify application.. The problem is finding a reliable list of addresses to block. I found the mentionned-above one on reddit, but its seems to be far too obstructing. Searching with 'spotify' ad-servers' list' on Internet didnt return anything up-to-date and reliable so far for me. If you have any info, you are welcome. Some are mentionned on github but its not perfect... Maybe its possible to find it using tools like wireshark but I dont know enough to use it properly. Thank you again.
â Thierry
Mar 6 at 7:34
 |Â
show 1 more comment
up vote
3
down vote
up vote
3
down vote
While you could use /etc/hosts.deny
, hosts.deny only works with TCP wrapped applications such as ssh or xinetd. I would recommend using iptables
since it is a true firewall to your system. Just use something like this:
iptables -I INPUT -s 31.13.76.102 -j DROP
iptables -I INPUT -m iprange --src-range 216.58.192.0-216.58.223.255 -j DROP
iptables -I INPUT -m iprange --src-range 173.194.0.0-173.194.255.255 -j DROP
iptables -I INPUT -m iprange --src-range 74.125.136.0-74.125.136.255 -j DROP
iptables-save > /etc/sysconfig/iptables
The iprange
is a really cool module to use for situations such as this.
While you could use /etc/hosts.deny
, hosts.deny only works with TCP wrapped applications such as ssh or xinetd. I would recommend using iptables
since it is a true firewall to your system. Just use something like this:
iptables -I INPUT -s 31.13.76.102 -j DROP
iptables -I INPUT -m iprange --src-range 216.58.192.0-216.58.223.255 -j DROP
iptables -I INPUT -m iprange --src-range 173.194.0.0-173.194.255.255 -j DROP
iptables -I INPUT -m iprange --src-range 74.125.136.0-74.125.136.255 -j DROP
iptables-save > /etc/sysconfig/iptables
The iprange
is a really cool module to use for situations such as this.
edited Mar 5 at 20:24
Drakonoved
674518
674518
answered Mar 5 at 18:24
Jaken551
1678
1678
Thank you for your answer Jaken551. Three more questions please : #0 Should I start Iptables on my system before typing the filtering rules, if yes how ? #1 What is the command to start iptables at each boot (I run Majaro, an Arch-Linux based distribution whose init system is systemd) ? #2 There is no /etc/sysconfig directory on my defaukt configuration, which command do I have to type to make the filtration rules permanent ?
â Thierry
Mar 5 at 19:41
#0: You can edit theiptables
rules whether or not the service is running, starting it is up to you. #1: Runsystemctl enable iptables
in order to have iptables service start at boot. #2: For Arch-Linux theiptables
config file is/etc/iptables/iptables.rules
. Unfortunately, this is not created by default with Arch, but running theiptables-save /etc/iptables/iptables.rules
will create it for you :) Best of luck to you!
â Jaken551
Mar 5 at 21:30
Thank you for your answer Jaken551. It does filter the targets BUT ranges seem far too large and block part of interesting targets wheraes I only want to target advertisements...
â Thierry
Mar 6 at 0:27
What exactly are you trying to block? This is only blocking incoming connections. If you are trying to block advertisements, firewall rules are not really what you want.
â Jaken551
Mar 6 at 7:11
Yes, I want to block spotifi ad-server to get rid of commercials on the free account through the spotify application.. The problem is finding a reliable list of addresses to block. I found the mentionned-above one on reddit, but its seems to be far too obstructing. Searching with 'spotify' ad-servers' list' on Internet didnt return anything up-to-date and reliable so far for me. If you have any info, you are welcome. Some are mentionned on github but its not perfect... Maybe its possible to find it using tools like wireshark but I dont know enough to use it properly. Thank you again.
â Thierry
Mar 6 at 7:34
 |Â
show 1 more comment
Thank you for your answer Jaken551. Three more questions please : #0 Should I start Iptables on my system before typing the filtering rules, if yes how ? #1 What is the command to start iptables at each boot (I run Majaro, an Arch-Linux based distribution whose init system is systemd) ? #2 There is no /etc/sysconfig directory on my defaukt configuration, which command do I have to type to make the filtration rules permanent ?
â Thierry
Mar 5 at 19:41
#0: You can edit theiptables
rules whether or not the service is running, starting it is up to you. #1: Runsystemctl enable iptables
in order to have iptables service start at boot. #2: For Arch-Linux theiptables
config file is/etc/iptables/iptables.rules
. Unfortunately, this is not created by default with Arch, but running theiptables-save /etc/iptables/iptables.rules
will create it for you :) Best of luck to you!
â Jaken551
Mar 5 at 21:30
Thank you for your answer Jaken551. It does filter the targets BUT ranges seem far too large and block part of interesting targets wheraes I only want to target advertisements...
â Thierry
Mar 6 at 0:27
What exactly are you trying to block? This is only blocking incoming connections. If you are trying to block advertisements, firewall rules are not really what you want.
â Jaken551
Mar 6 at 7:11
Yes, I want to block spotifi ad-server to get rid of commercials on the free account through the spotify application.. The problem is finding a reliable list of addresses to block. I found the mentionned-above one on reddit, but its seems to be far too obstructing. Searching with 'spotify' ad-servers' list' on Internet didnt return anything up-to-date and reliable so far for me. If you have any info, you are welcome. Some are mentionned on github but its not perfect... Maybe its possible to find it using tools like wireshark but I dont know enough to use it properly. Thank you again.
â Thierry
Mar 6 at 7:34
Thank you for your answer Jaken551. Three more questions please : #0 Should I start Iptables on my system before typing the filtering rules, if yes how ? #1 What is the command to start iptables at each boot (I run Majaro, an Arch-Linux based distribution whose init system is systemd) ? #2 There is no /etc/sysconfig directory on my defaukt configuration, which command do I have to type to make the filtration rules permanent ?
â Thierry
Mar 5 at 19:41
Thank you for your answer Jaken551. Three more questions please : #0 Should I start Iptables on my system before typing the filtering rules, if yes how ? #1 What is the command to start iptables at each boot (I run Majaro, an Arch-Linux based distribution whose init system is systemd) ? #2 There is no /etc/sysconfig directory on my defaukt configuration, which command do I have to type to make the filtration rules permanent ?
â Thierry
Mar 5 at 19:41
#0: You can edit the
iptables
rules whether or not the service is running, starting it is up to you. #1: Run systemctl enable iptables
in order to have iptables service start at boot. #2: For Arch-Linux the iptables
config file is /etc/iptables/iptables.rules
. Unfortunately, this is not created by default with Arch, but running the iptables-save /etc/iptables/iptables.rules
will create it for you :) Best of luck to you!â Jaken551
Mar 5 at 21:30
#0: You can edit the
iptables
rules whether or not the service is running, starting it is up to you. #1: Run systemctl enable iptables
in order to have iptables service start at boot. #2: For Arch-Linux the iptables
config file is /etc/iptables/iptables.rules
. Unfortunately, this is not created by default with Arch, but running the iptables-save /etc/iptables/iptables.rules
will create it for you :) Best of luck to you!â Jaken551
Mar 5 at 21:30
Thank you for your answer Jaken551. It does filter the targets BUT ranges seem far too large and block part of interesting targets wheraes I only want to target advertisements...
â Thierry
Mar 6 at 0:27
Thank you for your answer Jaken551. It does filter the targets BUT ranges seem far too large and block part of interesting targets wheraes I only want to target advertisements...
â Thierry
Mar 6 at 0:27
What exactly are you trying to block? This is only blocking incoming connections. If you are trying to block advertisements, firewall rules are not really what you want.
â Jaken551
Mar 6 at 7:11
What exactly are you trying to block? This is only blocking incoming connections. If you are trying to block advertisements, firewall rules are not really what you want.
â Jaken551
Mar 6 at 7:11
Yes, I want to block spotifi ad-server to get rid of commercials on the free account through the spotify application.. The problem is finding a reliable list of addresses to block. I found the mentionned-above one on reddit, but its seems to be far too obstructing. Searching with 'spotify' ad-servers' list' on Internet didnt return anything up-to-date and reliable so far for me. If you have any info, you are welcome. Some are mentionned on github but its not perfect... Maybe its possible to find it using tools like wireshark but I dont know enough to use it properly. Thank you again.
â Thierry
Mar 6 at 7:34
Yes, I want to block spotifi ad-server to get rid of commercials on the free account through the spotify application.. The problem is finding a reliable list of addresses to block. I found the mentionned-above one on reddit, but its seems to be far too obstructing. Searching with 'spotify' ad-servers' list' on Internet didnt return anything up-to-date and reliable so far for me. If you have any info, you are welcome. Some are mentionned on github but its not perfect... Maybe its possible to find it using tools like wireshark but I dont know enough to use it properly. Thank you again.
â Thierry
Mar 6 at 7:34
 |Â
show 1 more comment
up vote
0
down vote
Simply add the following to /etc/hosts.deny
:
ALL: 31.13.76.102
ALL: 216.58.192.0/19
ALL: 173.194.0.0/16
ALL: 74.125.136.0/24
add a comment |Â
up vote
0
down vote
Simply add the following to /etc/hosts.deny
:
ALL: 31.13.76.102
ALL: 216.58.192.0/19
ALL: 173.194.0.0/16
ALL: 74.125.136.0/24
add a comment |Â
up vote
0
down vote
up vote
0
down vote
Simply add the following to /etc/hosts.deny
:
ALL: 31.13.76.102
ALL: 216.58.192.0/19
ALL: 173.194.0.0/16
ALL: 74.125.136.0/24
Simply add the following to /etc/hosts.deny
:
ALL: 31.13.76.102
ALL: 216.58.192.0/19
ALL: 173.194.0.0/16
ALL: 74.125.136.0/24
edited Mar 5 at 18:45
answered Mar 5 at 18:03
DopeGhoti
40.2k54779
40.2k54779
add a comment |Â
add a comment |Â
up vote
0
down vote
The ufw
command (Uncomplicated FireWall, a simplified front-end for iptables, initially for Ubuntu, now also available for Debian and other distros) accepts CIDR range specifications, for instance:
ufw insert 1 deny from 31.13.76.102 # single address
ufw insert 1 deny from 216.58.192.0/18 # range
add a comment |Â
up vote
0
down vote
The ufw
command (Uncomplicated FireWall, a simplified front-end for iptables, initially for Ubuntu, now also available for Debian and other distros) accepts CIDR range specifications, for instance:
ufw insert 1 deny from 31.13.76.102 # single address
ufw insert 1 deny from 216.58.192.0/18 # range
add a comment |Â
up vote
0
down vote
up vote
0
down vote
The ufw
command (Uncomplicated FireWall, a simplified front-end for iptables, initially for Ubuntu, now also available for Debian and other distros) accepts CIDR range specifications, for instance:
ufw insert 1 deny from 31.13.76.102 # single address
ufw insert 1 deny from 216.58.192.0/18 # range
The ufw
command (Uncomplicated FireWall, a simplified front-end for iptables, initially for Ubuntu, now also available for Debian and other distros) accepts CIDR range specifications, for instance:
ufw insert 1 deny from 31.13.76.102 # single address
ufw insert 1 deny from 216.58.192.0/18 # range
answered Mar 5 at 21:05
xenoid
1,6751620
1,6751620
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f428332%2fhow-to-filter-ranges-of-ip-addresses%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
OK for filtering rules. Thank you for all the repliers. Now does someone know which addresses range to target for getting rid of advertisements on spotifi free accounts ? Thank you everyone.
â Thierry
Mar 6 at 0:33