search
HomeOperation and MaintenanceLinux Operation and MaintenanceHow to set up a network interface on Linux
How to set up a network interface on LinuxJul 05, 2023 pm 11:33 PM
linux network configurationNetwork interface settingslinux interface settings

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.

  1. 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.

  1. 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.

  1. 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.

  1. 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.

  1. 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!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Tutorial on finding keywords for common Linux commandsTutorial on finding keywords for common Linux commandsMar 05, 2025 am 11:45 AM

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

Work content of Linux operation and maintenance engineers What does Linux operation and maintenance engineers do?Work content of Linux operation and maintenance engineers What does Linux operation and maintenance engineers do?Mar 05, 2025 am 11:37 AM

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

How do I configure SELinux or AppArmor to enhance security in Linux?How do I configure SELinux or AppArmor to enhance security in Linux?Mar 12, 2025 pm 06:59 PM

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

How do I back up and restore a Linux system?How do I back up and restore a Linux system?Mar 12, 2025 pm 07:01 PM

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

How do I use regular expressions (regex) in Linux for pattern matching?How do I use regular expressions (regex) in Linux for pattern matching?Mar 17, 2025 pm 05:25 PM

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.

How do I monitor system performance in Linux using tools like top, htop, and vmstat?How do I monitor system performance in Linux using tools like top, htop, and vmstat?Mar 17, 2025 pm 05:28 PM

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

How do I implement two-factor authentication (2FA) for SSH in Linux?How do I implement two-factor authentication (2FA) for SSH in Linux?Mar 17, 2025 pm 05:31 PM

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

Methods for uploading files for common Linux commandsMethods for uploading files for common Linux commandsMar 05, 2025 am 11:42 AM

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,

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

mPDF

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

Notepad++7.3.1

Easy-to-use and free code editor

Safe Exam Browser

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.