Analysis and description of network configuration files under Ubuntu system

Analysis and description of network configuration files under Ubuntu system

I encountered a strange network problem today. I recorded the research process and some configuration situations, and learned about the network environment configuration under Linux.

Network Configuration Files

This file configures the network card information vi /etc/network/interfaces

auto lo
iface lo inet loopback
# Configure eth0 dhcp to obtain IP address auto eth0
iface eth0 inet dhcp

The role of configuration

There may be some configurations in /etc/network/interfaces, such as

auto lo
iface lo inet loopback

These two lines indicate that the auto lo system automatically configures the lo interface when it starts, and then configures a local loopback address for the lo interface.

If you want to configure a static address for the network card

auto eth0
iface eth0 inet static
 address 192.168.2.100
 network 192.168.2.0
 netmask 255.255.255.0
 broadcast 192.168.0.255
 gateway 192.168.0.1

The following lines represent the IP, network number, mask, broadcast address and gateway of the eth0 interface respectively.

If you want to configure DHCP to automatically obtain an IP address

auto eth0
iface eth0 inet dhcp

For more configuration information, see man interfaces

Go to the /etc/network directory and you will find many interesting directories.

if-down.d
if-post-down.d
if-pre-up.d
if-up.d

These directories are all network configurations implemented in Debian. When if-up occurs, the scripts placed in the if-up.d directory will be executed. This can be used to achieve some interesting things. For example, if you write a sign-in script, you can automatically sign in when the laptop is connected to the Internet, or start the VPN after connecting to the Internet.

Add execute permissions

chmod 755 /etc/network/if-up.d/YOUR_SCRIPT

Note that scripts are executed in lexicographic order.

Another way is to define the script in /etc/NetworkManager/dispatcher.d/, which can do the same thing, but it depends on NetworkManager.

Configure DNS

The DNS configuration file is in the /etc/resolv.conf file, which is usually

search domain
nameserver 127.0.0.53

Restart the network card

sudo ifup eth0
sudo ifdown eth0
# or
sudo ifconfig eth0 down
sudo ifconfig eth0 up

Restart the network

sudo /etc/init.d/networking restart
sudo /etc/init.d/network-manager restart

Summarize

The above is the full content of this article. I hope that the content of this article will have certain reference learning value for your study or work. Thank you for your support of 123WORDPRESS.COM.

You may also be interested in:
  • How to modify network configuration using Ubuntu command line
  • Ubuntu 10.10 network configuration

<<:  Install mysql 5.6 from yum source in centos7.4 system

>>:  Using JS timer to move elements

Recommend

Example of how to change the line spacing of HTML table

When using HTML tables, we sometimes need to chan...

Detailed explanation of Nginx configuration required for front-end

Nginx (engine x) is a lightweight, high-performan...

Native js canvas to achieve a simple snake

This article shares the specific code of js canva...

Detailed explanation of the basic usage of VUE watch listener

Table of contents 1. The following code is a simp...

Specific use of GNU Parallel

what is it? GNU Parallel is a shell tool for exec...

Mysql database master-slave separation example code

introduce Setting up read-write separation for th...

Complete steps to use vue-router in vue3

Preface Managing routing is an essential feature ...

Bootstrap 3.0 study notes for beginners

As the first article of this study note, we will ...

4 ways to modify MySQL root password (summary)

Method 1: Use the SET PASSWORD command First log ...

Vue implements small search function

This article example shares the specific code of ...

N ways to align the last row of lists in CSS flex layout to the left (summary)

I would like to quote an article by Zhang Xinxu a...

Detailed analysis of MySQL instance crash cases

[Problem description] Our production environment ...

Detailed example of Linux all-round system monitoring tool dstat

All-round system monitoring tool dstat dstat is a...