How do you configure IPTables so that it will only allow SSH in, and allow no other traffic in or out?
Any safety precautions anyone can recommend?
I have a server that I believe has been migrated away from GoDaddy successfully and I believe is no longer in use.
But I want to make sure just because ... you never know. :)
Note that this is a virtual dedicated server from GoDaddy... That means no backup and virtually no support.
You need just to set the default policy to DROP on the INPUT and OUTPUT chains.
To allow SSH in, you need the following commands:
The last two commands allow loopback traffic as this is required by some applications to function correctly. You can restrict the SSH access from specific IP using
-s source_ip
option.Executing the commands in order as shown above will cause your current SSH session to hang. This is because iptables commands take effect immediately. You need to execute them in a shell script to avoid losing the ability to connect to your machine when executing them remotely.
Something like this: