How to allow only ssh and internet access with iptables?

dmx

I want to allow only internet access (it is useful for update) and ssh on my server. I found this set of rules:

  sudo iptables -P INPUT DROP
  sudo iptables -P OUTPUT DROP
  sudo iptables -A INPUT -i lo -j ACCEPT
  sudo iptables -A INPUT -p tcp -m tcp --dport [port number] -j ACCEPT
  sudo iptables -A OUTPUT -o lo -j ACCEPT
  sudo iptables -A OUTPUT -p tcp --sport [port number] -m state --state ESTABLISHED -j ACCEPT
  sudo service iptables save
  sudo netfilter-persistent reload

This is working well but I can't update my system or access internet. Which rules should I add to allow outgoing internet connection?

2707974

Let's start

Delete curent rules and chains

sudo iptables --flush
sudo iptables --delete-chain

allow loopback

sudo iptables -A INPUT -i lo -j ACCEPT
sudo iptables -A OUTPUT -o lo -j ACCEPT

drop ICMP

sudo iptables -A INPUT -p icmp --icmp-type any -j DROP
sudo iptables -A OUTPUT -p icmp -j DROP

allow established connections

sudo iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT

allow SSH

sudo iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT

default policies

sudo iptables -P INPUT DROP
sudo iptables -P OUTPUT ACCEPT

Save

sudo iptables-save

This is it. I think :)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

iptables rule to allow access to internet

How can I allow SSH and SMTP only using IPTables?

iptables - how to allow internet but block subnet?

iptables: How to allow SSH through debian router?

How to only allow access to web server through SSH?

Allow internet access only through vpn server

How to allow only subnet for port with iptables

How do I allow only internal network to access a particular UDP Port using iptables

How to allow only apt internet access any deny / block everything else

How to restrict internet access to a subnet, and allow from only another subnet of the same vnet?

How to restrict internet access for a particular user on the lan using iptables in Linux

How to allow noip2 access through iptables with drop policy

How to allow only IPs ending with a specific number in IPTABLES?

Allow Egress only to internet

Ubuntu IPTables allow only allow 1 country

Block traffic to LAN but allow traffic to Internet (iptables)

What do I have to add to this iptables setup to allow mysql access through ssh?

Allow a UNIX group access to only a single file through SSH

How to restrict an SSH user to only allow SSH-tunneling?

How to only allow access thru an IFRAME

how to allow access to folders only for localhost in apache

IPTables rule to allow incoming SSH connections

How to allow access to an Angular 8 app from outside the network? (the internet)

How to allow only USB cable transfer and block internet on Windows Firewall?

Allow docker container to access the internet

How to allow traffic for SSH 22 using iptables for one specific ip address and internal networks

Set up firwall with iptables to only allow VPN

Linux - iptables allow only 3 IPs

is there an iptables rule to allow only email on port 25?