Configure Debian Network

Contents
Introduction
dhclient: Dynamic IP
Iproute2
Iproute2: Static IP
Enable / Disable network interface
Gateway
Change gateway
Change netmask
ifconfig
DHCP: Dynamic IP
ifconfig: Set static IP
Enagle / Disable Wi-Fi
DNS
netstat
List Open Ports
traceroute

To better navigate network administration, namely in concepts such as IP address types, masks, subnets, etc. I advise you to study the article

«Network Fundamentals»

Introduction

Setting up a network connection is a crucial step when working with Debian, which can cause The newbie has a lot of questions.

In this article you can find answers to some of them.

You can examine the file with the list of interfaces involved using the command

nano /etc/network/interfaces

Next, the setting depends on the version of Debian you are using.

On new versions of Debian. For example, Debian 9 uses Iproute2

If you need to set up a network on an old version of Debian using utilities ifconfig scroll down the page or go here

Dynamic IP with dhclient

Enable automatic IP acquisition

Flag -r flag explicitly releases the current lease, and once the lease has been released, the client exits.

For example, you can first run:

$ sudo dhclient -r

And then get a fresh IP address using DHCP

sudo dhclient

A similar operation can be performed for a specific interface

For example, foreth0

sudo dhclient -r eth0
sudo dhclient eth0

ВYou can enable automatic IP acquisition by pulling out the power cord and plugging it back in. They say that it should reset.

I advise you to do it

man interfaces

and examine the output.

Configuring network using Iproute2

Relevant for Debian 9 and above and other modern .deb distributions

You can set iproute2 with the command

sudo apt install -y iproute2

To get a list of interfaces, use the command

ip a

The names of the interfaces may differ from the usual eth0, eth1, and the like.

For example, we will assume that the interface is displayed as enp0s25

Iproute2: Set static IP

Example of assigning an IP address to the enp0s25 interface 10.0.2.16/24

sudo ip addr add 10.0.2.16/24 dev enp0s25

Enable/Disable the network interface

Enable enp0s25 interface:

ip link
set dev enp0s25 up

Disable enp0s25 interface:

ip link set dev enp0s25 down

Gateway

Delete the old network gateway

route delete default

Adding a new network gateway

route add default gw IP_Address

If there are a lot of old gateways, then you need to specify which specific IP to remove from which interface

route delete default gw 10.0.0.1 eth0

You can also specify specific data for creation

route add default gw 192.168.0.1 eth0

netmask

Find out your mask

ip r

default via 10.6.0.1 dev eth0
10.6.0.0/8 dev eth0 src 10.6.1.68

Delete the old one

ip address del 10.6.1.100/8 dev eth0

Add a new one

ip address add 10.6.1.68/22 dev eth0

Configuring the network using ifconfig

ifconfig is included in net-tools, so if it is not available by default, you can always install with the command

apt-get install net-tools

To get information about the available interfaces on older versions of Debian, use the command

ifconfig

Изучите вывод этой команды и посмотрите какой интерфейс Вам доступен. Обычно это eth0.

DHCP

If you need to get an ip automatically

iface eth0 inet dhcp

If you need to set a static ip

iface eth0 inet static
address 192.168.1.1
netmask 255.255.255.0

In order for the changes to take effect, you need to do

ifup eth0

Turn off wi-fi

ifconfig wlan0 down

Turn on/turn off the network

ifconfig eth0 up/down

Restart/stop/start network services

/etc/init.d/networking restart/stop/start

DNS

DNS can be configured via the /etc/resolv.conf file

nameserver 8.8.8.8

When was installed it was necessary to remember which network interfaces you are offered to configure Debian. This is very easy to do, they are called eth0, eth1 and so on.

Therefore, to enable the network interface, in the above command you need to change 0 to 1, etc.

However, if you install other Unix-like distributions, for example OpenBSD then the network interfaces will be called more variously (msk 0, sk0, etc.)

In order to avoid difficulties with this, it is useful to write down what is proposed to be configured when installing the distribution.

netstat

View the list of active network connections

netstat

Banner Image

Open ports

View the list of open ports

ss -ltupn

traceroute

To install traceroute, run

sudo apt-get install traceroute

Related Articles
Network setup
Debian
Add a network interface
Firewall
iftop: Network monitoring
nethogs: Network monitoring
tc: Traffic control
iperf: network speed change
Generate a GUID for the interface
Bash
SCP: edit files;
SSH: remote access
Sockets
C++

Search on this site

Subscribe to @aofeed channel for updates

Visit Channel

@aofeed

Feedback and Questions in Telegram

@aofeedchat