Set static IP under Centos

Many virtual machines are installed using VirtualBox, and DHCP is used by default. However, with more and more virtual machines, this method is very inconvenient, so it is necessary to set the IP of the machine to static IP

Explanation of several items that need to be added:

IPADDR IP address

NETMASK subnet mask

NETWORK gateway address

Generally, if we want to change the host address to a static address or change the host name, several files that need to be modified include:

/etc/sysconfig/network set host name and network configuration

/etc/sysconfig/network-scripts/ifcfg-eth0 Set up for specific network card

/etc/resolv.conf set DNS

/etc/hosts set the specified [domain name resolution] (https://cloud.tencent.com/product/cns?from=10680) address

Generally, we only need to modify the configuration file of the network card. For example, my configuration file is as follows:

DEVICE=eth0

BOOTPROTO=static

TYPE=Ethernet

NAME="System etho0"

BROADCAST=192.168.56.255

HWADDR=08:00:27:24:F8:9B

IPADDR=192.168.56.101

IPV6INIT=yes

IPV6_AUTOCONF=yes

NETMASK=255.255.255.0

NETWORK=192.168.56.1

ONBOOT=yes

After the setting is complete, restart the network card: service network restart

We also have another way to set a static IP, that is through the ifconfig command. Usually, we use it to view some information of the current network card, and at the same time, it can also be used to set some network card information.

The modified command is as follows: ifconfig eth0 192.168.56.102

However, after this command is executed, only the address of the network card can be modified in the current session. Let's take a look at the configuration file of ifcfg-eth0, and it is still

# Advanced Micro Devices [AMD] 79c970 [PCnet32 LANCE]

DEVICE=eth0

ONBOOT=yes

BOOTPROTO=dhcp

HWADDR=08:00:27:43:73:2f

In other words, after restarting the server, the IP will still be obtained according to the method in the configuration file.

Therefore, if you need to modify the IP to a static IP, the best way is to modify the configuration file.

Reference materials:

1、 Problems encountered when setting parameters with ifconfig

2、 Manually set the IP of CentOS

Recommended Posts

Set static IP under Centos
Configure static IP under CentOS 7
Ubuntu18.04, Centos7 static IP
Set static IP for CentOS in VMware
ubuntu16.04 set static ip
ubuntu 18.04 set static ip method
How to set static IP in ubuntu14.04
How to set static IP on Ubuntu 18.04 Server
How to set static IP on Ubuntu 18.04 Server
Explain how to set static IP on ubuntu14.04
ubuntu20.04 set static ip address (including different versions)
[Quick Start with Ubuntu] Two, Ubuntu set static IP
Explain the implementation of Centos8 static IP configuration
Deploy GitBook under CentOS7
ubuntu 17.10 set solid IP
Compile Hadoop-2.7.6 under CentOS7.4
Install ActiveMQ under Centos7
Install PostgreSQL12 under CentOS7
Install CentOS under VMware
Deploy JDK+Tomcat8 under CentOS
Install mysql under Centos 7
Configure lamp under centos6.8
Centos7 configure IP address
Install Jenkins under Centos 7
Redis3 installation under Centos7
Install MariaDB under MariaDB Centos7
Install mysql5.1 under CentOS6.5
Centos: add an IP address
Xen virtualization combat under CentOS 6.6
[CentOS environment deployment] Java7/Java8 deployment under CentOS
Build docker environment under Centos6.5
Build OpenV** Server under CentOS7
Build OpenLDAP server under CentOS7
Centos7 set up GitBook environment
Install Oracle11gR2 database under CentOS6.9
Install MySQL under Linux (CentOS 7)
Redis cluster installation under CentOS
Root password cracking under CentOS 7
Centos configure multiple virtual IP
SELinux security settings under CentOS
Install Java JDK8 under CentOS6
Centos6 set up GitBook environment
Set the network card to bridge mode under CentOS6.3 KVM
centos6.9 rabbitmq set up SSL
Install MongoDB database under CentOS7
CentOS 6.8 under linux install mongodb
Centos configure multiple virtual IP
Install Mesos tutorial under CentOS7
CentOS set ssh key login original
Install and configure keepalived under CentOS 5.9
CentOS 7 set up NTP, SSH service
Compile and install LAMP under Centos 5.2
[Introduction to redis] Install redis under Centos
RabbitMQ cluster deployment record under Centos6.9
Elasticsearch cluster deployment record under CentOS7
Deploy and optimize Tomcat under Centos
Install Harbor mirror warehouse under CentOS
Build an FTP server under centos7
Install Python3 and ansible under CentOS8
Install the latest OpenCV4.3 under Centos8
Install and use docker under CentOS 6.8