Spis treści

Linux: ip address

Setting up a network interface with a static address in Debian distributions

To set up a network interface with a static address in Debian, modify the configuration file /etc/network/interfaces. Here are the steps to follow.

Step 1: Edit the configuration file

Open a terminal and edit the /etc/network/interfaces file using a text editor such as nano or vim. Here is an example of using nano:

sudo nano /etc/network/interfaces

Step 2: Adding a static configuration

Add the configuration for the network interface in the file. Below is an example for interface eth0, which will get the IP address 192.168.1.100 with a subnet mask of 255.255.255.0 and a default gateway of 192.168.1.1.

# Ustawienia interfejsu Ethernet
auto eth0
iface eth0 inet static
    address 192.168.1.100
    netmask 255.255.255.0
    gateway 192.168.1.1
    dns-nameservers 8.8.8.8 8.8.4.4

Parameters

  
- address: The actual static IP address you want to assign to the interface.
- netmask: The subnet mask that is used for the local network.
- gateway: The IP address of the gateway (router) through which communication with other networks takes place.
- dns-nameservers: The addresses of the DNS servers that will be used for name resolution.
  

Step 3: Save changes and exit

If you are using nano, press CTRL + X, then Y and Enter to save your changes and exit the editor.

Step 4: Restart the web interface

To apply the new settings, restart the web interface. Use the following command:

sudo ifdown eth0 && sudo ifup eth0

If you are using a system where ifupdown can only be handled by systemd, you can also use:

sudo systemctl restart networking

Step 5: Check the configuration

To ensure that the interface has been successfully configured, use the command:

ip a

This command will display the configurations of all interfaces, including the assigned IP address.

By setting a network interface statically, you ensure that it will always have the same IP address, which is particularly useful for servers and systems that require stability in network communication.

Setting up a DNS server

Correct configuration of the DNS (Domain Name System) is essential for proper use of the Internet. To do this, you need to edit the two main configuration files:

/etc/host.conf: Defines how the name resolution function works.

Example file contents:

    order hosts,bind
    multi on

Sets that local host files will be searched first, followed by remote DNS servers.

/etc/resolv.conf: Contains the addresses of the DNS servers that will be used to resolve domain names.

Example of file:

    nameserver 8.8.8.8
    nameserver 8.8.4.4

This sets Google's DNS servers as default.

For ubuntu systems

Netplan is a network configuration tool for Ubuntu systems, introduced in versions 17.10 and later. It allows simple configuration of network interfaces and their settings.

Edit the configuration file:

The netplan configuration is stored in YAML files in the /etc/netplan/ directory. They can be edited with a text editor, such as:

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

Example file content for a static IP address:

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

Application of changes:

After editing the file, save the changes and exit. Then примените the configuration using the command:

    sudo netplan apply

Check configuration:

To ensure that the network interface is configured correctly, use:

    ip a

Notes

Netplan simplifies network configuration in Ubuntu by offering a flexible approach to connection management.