Brainstorm's snippets (1/267)

  Network Configuration in Debian 10

Preliminary downloads

Create the following VMs:

  • debian1 (root/debian1, master/debian1)
  • debian2 (root/debian2, master/debian2)

How to Install VirtualBox Guest Additions on Debian 10 Linux:

https://linuxize.com/post/how-to-install-virtualbox-guest-additions-on-debian-10/

Additional settings:

apt install net-tools
apt install sudo

echo 'export PATH=/usr/sbin:$PATH' >> ~/.bashrc


View current network configuration

$ ip a

or

$ ifconfig

To find out the DNS servers IPs:

$ cat /etc/resolv.conf


Change network configuration (temporary)

Basic network configuration includes setting:

  • a static or dynamic IP address
  • adding a gateway
  • adding DNS server information

The following commands will change network settings; however, the new settings will not be permanent: once you reboot your system, the settings will be removed.

1. Assign an IP address to the interface

sudo ifconfig <interface> <IP_address> netmask <subnetmask> up

example:

sudo ifconfig eth0 192.168.72.165 netmask 255.255.255.0 up

2. Set the Default Gateway

sudo route add default gw <IP_address> <interface>

example:

sudo route add default gw 192.168.72.2 eth0

3. Set Your DNS server

echo "nameserver <IP_address>" > /etc/resolv.conf

example:

echo "nameserver 8.8.8.8" > /etc/resolv.conf

4. Remove IP address from a network interface

ip address del <IP_address> dev <interface>

Once done, you can test your configuration by running the ifconfig command as follows:

sudo ifconfig -a


Change network settings permanently by using the interfaces file

Add a static address (file `/etc/network/interfaces`):

auto eth0

# static IP address
iface eth0 inet static
    address 192.168.72.165
    netmask 255.255.255.0
    gateway 192.168.72.2

Please note that the address, netmask and gateway line must start with leading whitespace!

Dynamically assign the address (file `/etc/network/interfaces`):

auto eth0
iface eth0 inet dhcp

Defining the (DNS) Nameservers

To add DNS server information, we will need to edit the /etc/resolv.conf file.

Example:

nameserver 8.8.8.8
nameserver 192.168.72.2

Reload network settings

ifdown eth0
ifup eth0


Configurazione DHCP server

sudo apt-get update
sudo apt-get install isc-dhcp-server

cat /etc/default/isc-dhcp-server

    INTERFACESv4="enp0s10"

cat /etc/dhcp/dhcpd.conf

    default-lease-time 600;
    max-lease-time 7200;

    subnet 192.168.100.64 netmask 255.255.255.224 {
        range 192.168.100.70 192.168.100.80;
        option routers 192.168.100.94;
        option domain-name-servers 8.8.8.8 8.8.4.4;
        option domain-name "acme.mo.it";

        #host TOR-datacenterclient {
        #    hardware ethernet 08:00:27:27:3a:1c;
        #    fixed-address 192.168.100.65;
        #}

    }

systemctl stop isc-dhcp-server
systemctl start isc-dhcp-server

tail -f /var/log/syslog


Comandi utili

ip addr
route
route -n
ip route