I am running Ubuntu server version 20.04. I have configured my ssh server to listen on an alternate port (port 40001) in my sshd_config file. I want to allow incoming traffic from anywhere on my local network (192.168.1.0/24) using TCP port 40001, and block all incoming traffic otherwise, particularly the wide area network (the rest of the internet). I do not want to be able to ssh into my server from outside of my local network.
EDIT: My setup is as follows...
- Main ISP Router, which has a public ip address, and then port forwards (80,443,40001) to a
- secondary router, which then port forwards (80,443,40001), to the Ubuntu server. The ubuntu server has a Wi-Fi card, as well as an ethernet adapter, however, only the wifi is being used. The Ubunut server is not being used as a router, but only as a webserver with ports 80,443, and ssh 40001 being utilized.
In short, here are my desired rules:
Allow port 40001/tcp on the local network (192.168.1.0/24). Deny everything else.
I would like to know how to do this from the command line in 2 different ways.
- The first way, would be using UFW (Uncomplicated Firewall).
- The second way would be to do this using iptables.
If anyone can help answer this, it would be much appreciated!