Skip to content

Ubuntu network management

swoellauer edited this page Jan 23, 2025 · 9 revisions

Web browser connectivity

Internet default port for HTTP is port 80 and default port for HTTPS is port 443. In a web browser you do not need to type the port numbers when that default ports are used.

Binding to low port numbers like port 80 and port 443 is allowed for root or sudo users only. You would need to run RSDB as root or sudo.
You should run RSDB as normal user, never as root or sudo.

Port forwarding

To use port port 80 and port 443 in RSDB you may create internal port forwarding:
port 80 (public HTTP port) to --> port 8080 (internal RSDB HTTP port)
port 443 (public HTTPS port) to --> port 8443 (internal RSDB HTTPS port)

You may use iptables directly. For a recommended way see section ufw firewall.
Following iptables rules are directly applied but removed after reboot.
To add the rules permanently, you need additional commands.

sudo iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080  
sudo iptables -t nat -A PREROUTING -p tcp --dport 443 -j REDIRECT --to-port 8443  

ufw firewall

It is recomended to activate a firewall on your server.
Here we configure the firewall ufw for usage with SSH and for RSDB.

Attention: An activated ufw blocks everything from the outside, including SSH, and a connection is no longer possible. It is best to do a backup to revert the following steps if something goes wrong, e.g. for a VM system, take a snapshot of the VM image first!

Add ufw rules for SSH, activate ufw and add ufw rules for RSDB:

# Show ufw status
sudo ufw status

# At first allow ssh!
sudo ufw allow ssh

# Or if there is no ssh profile
sudo ufw allow 22/tcp

# After adding ssh rule, start ufw
sudo ufw enable

# Show ufw status
sudo ufw status

# Reboot to check everything is OK
sudo reboot

# Show ufw status
sudo ufw status

# Add the RSDB ports that you provided in config.yaml
sudo ufw allow 8080/tcp
sudo ufw allow 8443/tcp

# Show ufw status
sudo ufw status

# Reboot to check everything is OK
sudo reboot

Start RSDB server and check with your web browser to access the RSDB port 8080 and port 8443.
At this point the port 80 and port 443 should not work.

Add ufw port forwarding rules:
Edit the file as root or sudo: /etc/ufw/before.rules e.g. sudo mcedit /etc/ufw/before.rules
An unchanged file contains one section starting with *filter and ending with COMMIT
At the end of the file after the COMMIT add the new section *nat:

*nat
:PREROUTING ACCEPT [0:0]
-A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080
COMMIT
*nat
:PREROUTING ACCEPT [0:0]
-A PREROUTING -p tcp --dport 443 -j REDIRECT --to-port 8443
COMMIT

Save the file and restart ufw:

sudo systemctl restart ufw
sudo ufw reload
sudo reboot

Start RSDB server and check with your web browser to access the RSDB ports 8080 and port 8443.
Now also check the port 80 and port 443 or the http and https URLs without port number, which now should work.

ufw firewall allow rules for port 80 and port 443 are not needed as the port forwarding step is applied before the firewall rules.

Clone this wiki locally