Setup static ip linux

How to Configure Static IP Address on Ubuntu 22.04

After installing Ubuntu 22.04 the default network interface assigns an IP address using the DHCP server. Also, the wireless network will be active and enable networking over the wifi network.

You can also configure the network interface with static IPv4 addresses. Ubuntu 22.04 uses the Netplan as a network manager.

This tutorial helps you to configure network interfaces on Ubuntu 22.04 Desktop and Ubuntu 22.04 Server editions. The desktop users can use any one of the below methods but the server users that have CLI only access use the second method to edit network interface configuration files.

Method 1: Configuring Static IPv4 Address on Ubuntu 22.04 Desktop

The Ubuntu Desktop editions have a graphical interface for configuring the network interfaces. Follow the below steps to configure a static IP address on Ubuntu 22.04 Desktop system.

    • Click the network icon in the upper-right corner.
    • Then expand the Wired Connected dropdown.
    • Now, click on Wired Setting as shown below image.

Configuring Static IP on Ubuntu 22.04

    • A network settings dialog box will appear.
    • Now, click “Network” in left sidebar.
    • Under the Wired section, click the Gear icon as showing in below image

    Configuring Static IP on Ubuntu 22.04

    • A new Wired dialog box will appear.
    • Now, click on “IPv4” tab.
    • Set IPv4 Method to Manual
    • Input a valid IP address, Netmark and Gateway address
    • Set the DNS server (optional)
    • Click Apply button to save changes

    Configuring Static IP on Ubuntu 22.04

  • Finally disable and then again enable networking to apply changes. Configure Static IP Address on Ubuntu 22.04
  • All done. Ubuntu Desktop system IP address is now changed.
  • Method 2: Configuring Static IPv4 Address on Ubuntu 22.04 Server with CLI

    Server editions are installed without any graphical interface. In that case, you need to configure the IP address using the command line.

    Ubuntu uses the Netplan as a network manager that is responsible for configuring the network interfaces. Follow the below steps:

      First, find out the network interface name in your system. The interface name can differ based on the installation type and system hardware. To find the interface name type:

    Configure Static IPv4 Address using Netplan on Ubuntu

    The above output shows that the system is configured with the network interface name eth0. This can be different on your system.
    Now, create or edit the network configuration file under the /etc/netplan directory. Create a configuration file and edit it in an editor:

    sudo vi /etc/netplan/01-netcfg.yaml 

    Источник

    How to Set Static IP Address and Configure Network in Linux

    If you are a Linux system administrator, time will come when you will need to configure networking on your system. Unlike desktop machines where you can use dynamic IP addresses, on a server infrastructure, you will need to setup a static IP address (at least in most cases).

    This article is meant to show you how to configure static IP address on most frequently used Linux distributions.

    For the purpose of this tutorial, we will use the following Internet Protocol version 4 (IPv4) details:

    IP address: 192.168.0.100 Netmask: 255.255.255.0 Hostname: node01.tecmint.com Domain name: tecmint.com Gateway: 192.168.0.1 DNS Server 1: 8.8.8.8 DNS Server 2: 4.4.4.4

    Configure Static IP Address in RHEL/CentOS/Fedora:

    To configure static IP address in RHEL / CentOS / Fedora, you will need to edit:

    /etc/sysconfig/network /etc/sysconfig/network-scripts/ifcfg-eth0

    Where in the above «ifcfg-eth0″ answers to your network interface eth0 . If your interface is named “ eth1» then the file that you will need to edit is «ifcfg-eth1» .

    Let’s start with the first file:

    NETWORKING=yes HOSTNAME=node01.tecmint.com GATEWAY=192.168.0.1 NETWORKING_IPV6=no IPV6INIT=no
    # vi /etc/sysconfig/network-scripts/ifcfg-eth0

    Note: Make sure to open the file corresponding to your network interface. You can find your network interface name with ifconfig -a command.

    In that file make the following changes:

    DEVICE="eth0" BOOTPROTO="static" DNS1="8.8.8.8" DNS2="4.4.4.4" GATEWAY="192.168.0.1" HOSTNAME="node01.tecmint.com" HWADDR="00:19:99:A4:46:AB" IPADDR="192.68.0.100" NETMASK="255.255.255.0" NM_CONTROLLED="yes" ONBOOT="yes" TYPE="Ethernet" UUID="8105c095-799b-4f5a-a445-c6d7c3681f07"

    You will only need to edit the settings for:

    Other settings should have already been predefined.

    Next edit resolve.conf file by opening it with a text editor such as nano or vi:

    nameserver 8.8.8.8 # Replace with your nameserver ip nameserver 4.4.4.4 # Replace with your nameserver ip

    Once you have made your changes restart the networking with:

    # /etc/init.d/network restart [On SysVinit] # systemctl restart network [On SystemD]

    Set Static IP Address in Debian / Ubuntu

    To setup static IP address in Debian/ Ubuntu, open the following file:

    # nano /etc/network/interfaces

    You may see a line looking like this:

    auto eth0 iface eth0 inet dhcp

    Change it so it looks like this:

    auto eth0 iface eth0 inet static address 192.168.0.100 netmask 255.255.255.0 gateway 192.168.0.1 dns-nameservers 4.4.4.4 dns-nameservers 8.8.8.8

    Save the file and then edit /etc/resolv.conf like this:

    nameserver 8.8.8.8 # Replace with your nameserver ip nameserver 4.4.4.4 # Replace with your nameserver ip

    Restart the networking on your system with:

    # /etc/init.d/network restart [On SysVinit] # systemctl restart network [On SystemD]

    Your static IP address has been configured.

    Conclusion:

    You now know how to configure a static IP address on a Linux distro. If you have any questions or comments, please do not hesitate to submit them in the comment section below.

    Источник

    Set static IP in Ubuntu using Terminal

    Static IP in Ubuntu

    Normally, the router’s DHCP server handles assigning the IP address to every device on the network, including your computer.

    The DHCP server may also give you a new IP address occasionally. This could cause a problem if you have a home lab or server setup that works on a fixed IP address.

    You need to set a static IP address on your Ubuntu system to avoid problems.

    Step 1: Identify the correct network interface

    The first step is always to know the name of your network interface.

    «But why?» you might ask. That is because since Ubuntu 20.04, the network interfaces are named using predictable network interface names. This means your one and only ethernet interface will not be named ‘eth0’.

    Ubuntu Server and Ubuntu Desktop use different renderers for ‘netplan’, they are ‘systemd-networkd’ and ‘NetworkManager’, respectively. So let’s go over their differences.

    Ubuntu Server

    To see available network interfaces on Ubuntu Server, run the following command:

    Doing so will show a similar result:

    $ ip link 1: lo: mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 2: enp1s0: mtu 1500 qdisc fq_codel state UP mode DEFAULT group default qlen 1000 link/ether 52:54:00:43:48:1f brd ff:ff:ff:ff:ff:ff

    The output enumerates network interfaces with numbers.

    From this, I can see that the ethernet interface is ‘enp1s0’.

    Ubuntu Desktop

    The advantage (at least in my opinion) of having Ubuntu Desktop is having NetworkManager as the renderer for netplan.

    It has a pretty CLI output 🙂

    Run the following command to view the available network interfaces:

    That will give you the device name, type, state and connection status.

    Here is what it looks like on my computer:

    $ nmcli device status DEVICE TYPE STATE CONNECTION enp1s0 ethernet connected Wired connection 1 lo loopback unmanaged --

    This is more readable at first glance. I can make out that my ethernet interface is named ‘enp1s0’.

    Step 2: See current IP address

    Now that you know which interface needs to be addressed, let us edit a file.

    Before I change my IP address/set a static one, let us first see what my current IP address is.

    Nice! But let’s change it to ‘192.168.122.128’ for demonstration purposes.

    Step 3: See the gateway

    A gateway is a device that connects different networks (basically what your all-in-one router is). To know the address of your gateway, run the following command:

    The gateway address will be on the line that begins with «default via».

    Below is the output of running the ip command on my computer:

    $ ip route default via 192.168.122.1 dev enp1s0 proto static 192.168.122.0/24 dev enp1s0 proto kernel scope link src 192.168.122.69

    On the line that starts with «default via», I can see that my gateway address ‘192.168.122.1’

    Make a note of your gateway address.

    Step 4: Set static IP address

    Now that you have detail like interface name and gateway address, it is time to edit a config file.

    Step 4-A: Disable cloud-init if present

    The easiest way to know if cloud-init is present or not is to check if there is a package with that name.

    Run the following command to check:

    apt-cache pkgnames | grep cloud-init

    If you get an outupt, you have ‘cloud-init’ installed.

    Now, to disable could-init, create a new file inside the /etc/cloud/cloud.cfg.d directory. The name does not matter, so I will call it ’99-disable-cloud-init.cfg’.

    sudoedit /etc/cloud/cloud.cfg.d/99-disable-cloud-init.cfg

    Add the following line to it:

    Please reboot your Ubuntu system now so that cloud-init does not interfere when we set our static IP address in the next step. 🙂

    Back to Step 4

    Once the ‘cloud-init’ related configuration is complete, we must now edit the netplan configuration to add our static IP address.

    Go to the /etc/netplan directory. It is better if there is one file (easier to know which one to edit), but in some cases, there might also be more than one file with the extension ‘.yml’ or ‘.yaml’.

    When in doubt, grep for the name of your network interface. Use the following command if you are not comfortable with grep:

    Since the name of network interface for my ethernet is ‘enp1s0’, I will run the following command:

    $ grep -iH enp1s0 *.* 00-installer-config.yaml: enp1s0:

    running this command shows that the file I am looking for is ’00-installer-config.yaml’. So let us take a look at it.

    network: ethernets: enp1s0: dhcp4: true version: 2

    You might have noticed a line that says ‘ethernet’ and our network interface name under that. Under this is where we configure our ‘enp1s0’ network interface.

    Since we do not want DHCP assigned IP address, let us change that field from true to no .

    Add a field called addresses . Write the IP address you wish to assign your computer along with the network prefix. So I will write 192.168.122.128/24 in the addresses field.

    Finally, we also need to specify DNS nameservers. For that, create a new field called nameservers and under that, create a field called addresses which contains the IP address for your DNS servers. I used Cloudflare’s DNS servers but you can use whatever you want.

    This is what my ’00-installer-config.yaml’ file looks like after editing it to my liking.

    network: ethernets: enp1s0: dhcp4: no addresses: - 192.168.122.128/24 gateway4: 192.168.122.1 nameservers: addresses: [1.1.1.1, 1.0.0.1] version: 2

    To apply the settings, run the following command:

    This will take only a few seconds, and the IP address will be updated once it is done.

    You can check the IP address using the hostname -I command.

    Perfect! The IP address has now changed successfully.

    I know that it feels complicated but this is the proper procedure when you are trying to assign static IP via the command line in Ubuntu.

    Let me know if you are stuck at some point or encounter any technical issues.

    Источник

    Читайте также:  Document Moved
    Оцените статью
    Adblock
    detector