


How to set up a network interface on Linux
The network interface is an important part of the computer system. It is responsible for connecting the communication between the computer and the network. Setting up a network interface in a Linux system is a very common task. This article will introduce how to set up a network interface on Linux, with code examples.
- Check the status of the network interface
Before you start setting up the network interface, you first need to check the status of the network interface in the current system. You can use the following command to view the network interface information in the current system:
$ ifconfig
This command will display all network interfaces in the current system and their related information, such as interface name, IP address, subnet mask, etc. Find the network interface you want to set up as needed.
- Configuring the network interface
In Linux, you can use the ifconfig command to temporarily configure a network interface. Here is a common example, this command will configure an interface named eth0, set the IP address to 192.168.0.1, and the subnet mask to 255.255.255.0:
$ ifconfig eth0 192.168.0.1 netmask 255.255.255.0
This command sets the IP address of the interface and subnet mask. If no subnet mask is specified, 255.255.255.0 is used by default.
- Set the default gateway
If you need to use a specific network interface as the default gateway, you can use the following command to set it:
$ route add default gw 192.168.0.254
The above command will Set the default gateway to 192.168.0.254. This is a common setting used to specify the gateway address to which all non-local traffic is sent.
- DNS Server
When setting up the network interface, you also need to consider the settings of the DNS server so that the computer can access the Internet through domain name resolution. In Linux systems, you can set up the DNS server by modifying the /etc/resolv.conf file.
The file can be opened with the following command:
$ sudo vi /etc/resolv.conf
In the editor that opens, add the following lines to set up the DNS server:
nameserver 8.8.8.8 nameserver 8.8.4.4
The above example will set up two Google The public DNS server serves as the system's DNS server. Additional DNS servers can be added as needed.
- Permanent setting of network interface
The settings in the above example are temporary and will be lost after the system is restarted. If you want these settings to be preserved across system startup, you need to add them to the network configuration file.
In most Linux distributions, the configuration file for network interfaces is located in /etc/network/interfaces. Open the file for editing using the following command:
$ sudo vi /etc/network/interfaces
Add the following content at the end of the file:
auto eth0 iface eth0 inet static address 192.168.0.1 netmask 255.255.255.0 gateway 192.168.0.254 dns-nameservers 8.8.8.8 8.8.4.4
The above example will configure the IP address, subnet mask, default gateway, and DNS server of the eth0 interface . It can be modified according to the actual situation. After saving the file, restart the system for the settings to take effect.
Summary
This article introduces how to set up a network interface on a Linux system and provides relevant code examples. Setting up network interfaces is a common task in Linux system administration, and mastering these basic operations is essential for network configuration and connectivity. I hope readers can better configure and manage network interfaces in Linux systems through the guidance of this article.
The above is the detailed content of How to set up a network interface on Linux. For more information, please follow other related articles on the PHP Chinese website!

This tutorial demonstrates efficient keyword searching in Linux using the grep command family and related tools. It covers basic and advanced techniques, including regular expressions, recursive searches, and combining commands like awk, sed, and xa

This article details the multifaceted role of a Linux system administrator, encompassing system maintenance, troubleshooting, security, and collaboration. It highlights essential technical and soft skills, salary expectations, and diverse career pr

This article compares SELinux and AppArmor, Linux kernel security modules providing mandatory access control. It details their configuration, highlighting the differences in approach (policy-based vs. profile-based) and potential performance impacts

This article details Linux system backup and restoration methods. It compares full system image backups with incremental backups, discusses optimal backup strategies (regularity, multiple locations, versioning, testing, security, rotation), and da

The article explains how to use regular expressions (regex) in Linux for pattern matching, file searching, and text manipulation, detailing syntax, commands, and tools like grep, sed, and awk.

The article discusses using top, htop, and vmstat for monitoring Linux system performance, detailing their unique features and customization options for effective system management.

The article provides a guide on setting up two-factor authentication (2FA) for SSH on Linux using Google Authenticator, detailing installation, configuration, and troubleshooting steps. It highlights the security benefits of 2FA, such as enhanced sec

This article compares Linux commands (scp, sftp, rsync, ftp) for uploading files. It emphasizes security (favoring SSH-based methods) and efficiency, highlighting rsync's delta transfer capabilities for large files. The choice depends on file size,


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 Mac version
God-level code editing software (SublimeText3)

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Notepad++7.3.1
Easy-to-use and free code editor

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.
