Skip to content

Instantly share code, notes, and snippets.

@andmax
Last active June 9, 2020 13:47
Show Gist options
  • Save andmax/0ebec81fd542b245aecb6678715cfe13 to your computer and use it in GitHub Desktop.
Save andmax/0ebec81fd542b245aecb6678715cfe13 to your computer and use it in GitHub Desktop.
About IP address/subnet number or the slash notation to define sub-net masks
1- Understand slash notation and subnet mask as:
2- IP address / number of 1's in the subnet mask, i.e.:
3- An IP of 192.168.42.23 with a subnet mask of 255.255.255.0
4- Will have a slash notation as: 192.168.42.23/24
5- That is there are 24 number ones in 255.255.255.0 or
6- 11111111.11111111.11111111.00000000
7- A subnet mask says what parts of the IP address can change (0)
8- and cannot change (1), so the above mask (255.255.255.0) is
9- saying only the last part of the IP address can vary or: 192.168.42.*
10- When using iptables to setup rules to access a host machine
11- The order of the rules are important, so to block all
12- IP addresses but a range of IPs to access a specifc port range
13- The following commands can be used:
sudo iptables -A INPUT -p tcp --destination-port 9001:9010 --source 192.168.42.0/24 -j ACCEPT
sudo iptables -A INPUT -p tcp --destination-port 9001:9010 -j DROP
14- In this order, so the allowed IP addresses in --source pass through
15- And all other IP addresses are dropped (blocked) for the specific
16- Port range defined in --destination-port
17- To reset all rules run:
sudo iptables -F
18- To check the order of rules to be applied run:
sudo iptables -S
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment