Skip to content

Setting Up the Network on a New Ubuntu Server

Step 1: Update and Upgrade the System

First, ensure your system is up to date:

bash
sudo apt update
sudo apt upgrade -y

Step 2: Configure the Firewall

Ubuntu comes with UFW (Uncomplicated Firewall) by default. Enable and configure it:

bash
sudo ufw enable
sudo ufw allow ssh
sudo ufw allow http
sudo ufw allow https
sudo ufw status

Step 3: Set Up IP Tables

IPTables can be used for more advanced network configurations:

bash
sudo apt install iptables

Create a basic IP tables configuration:

bash
sudo iptables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
sudo iptables -A INPUT -p tcp --dport 22 -j ACCEPT
sudo iptables -A INPUT -p tcp --dport 80 -j ACCEPT
sudo iptables -A INPUT -p tcp --dport 443 -j ACCEPT
sudo iptables -A INPUT -j DROP

Save the IP tables configuration:

bash
sudo sh -c "iptables-save > /etc/iptables/rules.v4"

Step 4: Configure Network Interfaces

Edit the network interfaces configuration file:

bash
sudo nano /etc/netplan/01-netcfg.yaml

Example configuration:

yaml
network:
  version: 2
  ethernets:
    eth0:
      dhcp4: no
      addresses:
        - 192.168.1.100/24
      gateway4: 192.168.1.1
      nameservers:
        addresses:
          - 8.8.8.8
          - 8.8.4.4

Apply the configuration:

bash
sudo netplan apply

Step 5: Additional Security Policies

Disable root login via SSH:

bash
sudo nano /etc/ssh/sshd_config

Set PermitRootLogin to no:

plaintext
PermitRootLogin no

Restart SSH service:

bash
sudo systemctl restart ssh

Step 6: CoreUtils and Additional Tools

Install coreutils and other useful tools:

bash
sudo apt install coreutils htop vim

Conclusion

Your Ubuntu server network is now configured with a firewall, IP tables, and additional security policies.