Skip to content

How to Set Static IP on Ubuntu

  • by

What is a Static IP and What is the Use of Static IP on Linux Systems?

A static IP (Internet Protocol) address is a fixed, assigned IP address that is assigned to a device on a network. In contrast, a dynamic IP address is a temporary address that is assigned to a device by a DHCP (Dynamic Host Configuration Protocol) server.

On a Linux system, you can use a static IP address to identify a device on a network and allow it to communicate with other devices on the network. A static IP address can be useful in a number of situations, including:

  • Running a server or hosting services: A static IP address allows you to access your server or services from other devices on the network using a consistent, fixed IP address.
  • Connecting to a remote desktop: A static IP address allows you to easily connect to a remote desktop or other remote access service using a fixed IP address.
  • Configuring a VPN (Virtual Private Network): A static IP address can be used to configure a VPN connection, allowing you to securely connect to a remote network over the internet.

Using a static IP address can be useful in these and other scenarios, but it also has some limitations. For example, if you need to access the internet from multiple locations, you may need to manually update your network configuration each time you change locations. In contrast, a dynamic IP address is automatically assigned by a DHCP server, which can simplify the process of connecting to a network.

Refer to the documentation for your Linux distribution and network configuration tools for more information on configuring static IP addresses on a Linux system.

How to Set Static IP on Ubuntu

To set a static IP address on an Ubuntu system, you will need to modify the network configuration files.

  1. Open the network configuration file for your network interface in a text editor. The file is typically located at /etc/network/interfaces.
sudo vim /etc/network/interfaces
  1. Find the entry for your network interface, which will be in the form of iface eth0 inet dhcp for a wired connection or iface wlan0 inet dhcp for a wireless connection.
  2. Change dhcp to static to configure a static IP address for the interface.
  3. Add the following lines below the iface entry, replacing the placeholders with your desired static IP address, netmask, and gateway:
address <static IP address>
netmask <netmask>
gateway <gateway>

For example:

iface eth0 inet static
address 192.168.1.100
netmask 255.255.255.0
gateway 192.168.1.1
  1. Save the file and exit the text editor.
  2. Restart the network service to apply the changes:
sudo service networking restart

Alternatively, you can use the ip command to configure a static IP address for your network interface. For example, the following command will set the static IP address 192.168.1.100, netmask 255.255.255.0, and gateway 192.168.1.1 for the eth0 interface:

sudo ip addr add 192.168.1.100/24 dev eth0
sudo ip route add default via 192.168.1.1 dev eth0

Note: These steps assume that you are using the systemd-networkd service to manage your network interfaces. If you are using a different networking service, the steps and commands may vary.

Refer to the Ubuntu documentation and the ip command documentation for more information on configuring network interfaces and static IP addresses.

Visited 1 times, 1 visit(s) today

Leave a Reply

Your email address will not be published. Required fields are marked *