How to configure an IP address in Linux networking settings?

To set up an IP address for a Linux network, you can follow these steps:

  1. Open the terminal and log in as a root user.
  2. Use the following command to view the current network configuration:
ifconfig
  1. Identifying the network interface that needs to be configured, typically it would be eth0 or ens33.
  2. Edit the network configuration file using the following command:
vi /etc/sysconfig/network-scripts/ifcfg-eth0
  1. Add the following content to the file, modifying it as needed based on the actual situation.
DEVICE=eth0
BOOTPROTO=static
ONBOOT=yes
IPADDR=192.168.0.100
NETMASK=255.255.255.0
GATEWAY=192.168.0.1
DNS1=8.8.8.8
DNS2=8.8.4.4

其中,DEVICE是指网络接口的名称,BOOTPROTO是指网络的配置方式(静态表示使用固定IP,动态则表示动态获取IP),IPADDR指的是IP地址,NETMASK是指子网掩码,GATEWAY是指网关地址,DNS1和DNS2则表示DNS服务器的地址。

  1. Save and exit the file.
  2. Restart the network service using the following command:
service network restart
  1. Use the following command to view the network configuration again:
ifconfig

Confirm that the IP address has been successfully configured.

Please note that the above steps are only applicable to Linux distributions such as CentOS or Red Hat that use the ifcfg file for configuring networks. Other distributions may have different configuration files and commands.

bannerAds