Protecting A Server With Iptables and Iptstate
Protecting A Server With Iptables and Iptstate
)
What You Need
An Ubuntu or Kali Linux VM, as you prepared in the previous project. Other versions of Linux could be used, but the steps might be different.
You also need another machine to test the connection from, on the same network.
Purpose
To protect a server with the iptables firewall and monitor connections with iptstate.
A firewall is a very powerful defense and every server should use one.
sudo iptables -L
You should see three rules, showing "policy ACCEPT" for the three chains named INPUT, FORWARD, and OUTPUT, as shown below.
sudo iptables -F
sudo iptables -X
sudo iptables -t nat -F
sudo iptables -t nat -X
sudo iptables -t mangle -F
sudo iptables -t mangle -X
sudo iptables -t raw -F
sudo iptables -t raw -X
sudo iptables -t security -F
sudo iptables -t security -X
sudo iptables -P INPUT ACCEPT
sudo iptables -P FORWARD ACCEPT
sudo iptables -P OUTPUT ACCEPT
Blocking FORWARDING
If your server were being used as a router, forwarding traffic with network address translation, it would use this rule. But we aren't doing that, so block forwarding with this command:
Starting iptstate
On your Linux server, in a Terminal window, execute these command:
sudo iptstate
You see a display showing any active network connections. You may have none at all, but when I did it I saw one connection, as shown below.
ifconfig
nc -nlvp 9999
If you are using Linux or the Mac, connect with nc this way, replacing the IP address with the IP address of your Linux server:
nc 172.16.1.203 9999
If you are using Windows, install nmap and then connect this way:
sudo iptables -A OUTPUT -p tcp --tcp-flags ALL SYN -m state --state NEW -j DROP
Click the host computer's desktop. Press Shift+PrntScrn key to capture the entire desktop. If you are using a Mac, press Shift+Cmd+3
Save this image with the filename "Proj 7x from YOUR NAME"
Sources
Simple stateful firewall