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

How to use mysqldump to backup MySQL data

1. Introduction to mysqldump mysqldump is a logic...

Detailed example of Linux all-round system monitoring tool dstat

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

How are spaces represented in HTML (what do they mean)?

In web development, you often encounter characters...

A brief discussion on MySQL large table optimization solution

background The amount of new data in the business...

Sample code for installing ASPNET.Core3.0 runtime in Linux

# The following examples are for x64-bit runtime ...

How to delete all contents in a directory using Ansible

Students who use Ansible know that Ansible only s...

mysql creates root users and ordinary users and modify and delete functions

Method 1: Use the SET PASSWORD command mysql -u r...

Solution for creating multiple databases when Docker starts PostgreSQL

1 Introduction In the article "Start Postgre...

Set IE8 to use IE7 style code

<meta http-equiv="x-ua-compatible" co...

HTML+CSS to achieve layered pyramid example

This article mainly introduces the example of imp...

How Web Designers Create Images for Retina Display Devices

Special statement: This article is translated bas...

Web project development VUE mixing and inheritance principle

Table of contents Mixin Mixin Note (duplicate nam...

JavaScript object built-in objects, value types and reference types explained

Table of contents Object Object Definition Iterat...