Temporarily modify IP address, gateway, host name, DNS, immediately effective, no reboot (failure after reboot)
1. Modify Host Name
The code is as follows:
#hostname Slyar
2. Modify IP address (eth0 is the name of the network card)
The code is as follows:
#ifconfig eth0 192.168.1.5 netmask 255.255.255.0
3. Modify the default gateway (Eth0 is the name of the network card)
The code is as follows:
#route add default GW 192.168.1.1 Dev eth0
4. Modify DNS
The code is as follows:
#vim/etc/resolv.conf
CentOS (RedHat) command line permanently modifies IP address, gateway, DNS
The command line permanently modifies IP addresses, gateways, and DNS
1. Modify IP Address
First check the number and name of your host network card, the relevant information under the/etc/sysconfig/network-scripts/.
I can see from the figure that I have 2 network cards, the first is Ethernet physical network card, number 0, if you have more than one network card, then numbered 0, 1, 2, 3 ...; The second network card is a loopback network card, generally do not need to set.
Use VIM edit you need to set IP network card, here I can only modify Ifcfg-eth0, look at the map, not many explanations, the previous state is Bootproto set to DHCP when the writing.
The code is as follows:
Vim/etc/sysconfig/network-scripts/ifcfg-eth0
The code is as follows:
Device=eth0 #网卡名称
Bootproto=static #获取ip的方式 (STATIC/DHCP/BOOTP), not explained
hwaddr=00:0c:29:b5:b2:69 #MAC地址
ipaddr=12.168.1.5 #IP地址
netmask=255.255.255.0 #子网掩码
network=192.168.1.0 #网络地址
broadcast=192.168.0.255 #广播地址
Nboot=yes #启动设备
2. Modify Gateway
The code is as follows:
Vim/etc/sysconfig/network
Add a gateway Message
The code is as follows:
gateway=192.168.1.1
3. Modify DNS
The code is as follows:
Vim/etc/resolv.conf
Adding DNS information can
The code is as follows:
NameServer 192.168.1.1
4. Reload Network Configuration
The code is as follows:
/etc/init.d/network restart