1. Modify Host Name
Temporary method:
Exit the current shell and log in again to take effect. This law can only be amended to take effect temporarily. Fails after rebooting the system.
Hint: Many people use the hostname hostname to modify, in fact this is only as temporary. Restore to pre-configured host name after reboot
Permanent method:
[Email protected] ~]# hostname greymouster
Tip: After this modification, the execution of/etc/init.d/network restart or source/etc/sysconfig/network will not take effect, if you want to modify this file may need to restart the server
[email protected] ~]# reboot
After the reboot, it will be permanently active.
Modify the/etc/hosts inside the corresponding hostname also to be modified under
[Email protected] ~]# vi/etc/hosts127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 greymouster::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
Hint: If/etc/hosts does not change, later will encounter some problems, such as SendMail start slowly, LDAP Service parsing is slow, sudo user slow and so on is the hostname and/etc/hosts in the resolution does not correspond to the resulting
2) network card configuration file Description:
[Email protected] ~]# Cat/etc/sysconfig/network-scripts/ifcfg-eth0device=eth0 #这里是网卡名称第一块网卡为eth0, the second block is eth1 .... hwaddr=00:0c:29:1f:b7:7b #这里是mac地址, different machines can not be duplicated, especially when cloning a virtual machine or replicating the network adapter configuration, pay attention to type=ethernet #类型UUID = 938bff60-0b1e-4ed3-9ff8-74eb8ba0ed57onboot=yes
dns1:8.8.8.8 #DNS
dns2:202.106.0.20 #DNSBOOTPROTO =static #是否是静态的ip地址IPADDR =192.168.1.169 #ip地址NETMASK =255.255.255.0 # Subnet Mask gateway=192.168.1.1
3) Configure the IP address to modify:
How to configure network configuration such as server IP and DNS:
Edit the above configuration file directly
ipaddr=192.168.1.169
[[email protected] ~]#/etc/init.d/network Restart closing interface eth0: [OK] close Loopback interface: [OK] Popup loopback interface: [OK] Popup interface Eth0:determinin G If IP address 192.168.1.169 is already on use for device eth0 ... Determine [[email protected] ~]# ifconfig eth0eth0 Link encap:ethernet HWaddr 00:0c:29:1f:b7:7b inet addr:192. 168.1.169 bcast:192.168.1.255 mask:255.255.255.0 inet6 addr:fe80::20c:29ff:fe1f:b77b/64 scope:link up Broadcast RUNNING multicast mtu:1500 metric:1 RX packets:42845 errors:3 dropped:0 overruns:0 frame:0 TX packets:2711 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:3406987 ( 3.2 MiB) TX bytes:332569 (324.7 KiB) interrupt:19 Base address:0x2000 [[email protected] ~]#
Ifup eth0 Start Network card
Ifdown eth0 turn off the NIC
Temporary configuration of two IP reboots will expire
[email protected] ~]# ifconfig eth0:0 192.168.1.168 netmask 255.255.255.0[[email protected] ~]# ifconfig Eth0 Link encap:ethernet HWaddr 00:0c:29:1f:b7:7b inet addr:192.168.1.169 bcast:192.168.1.255 mask:255. 255.255.0 Inet6 addr:fe80::20c:29ff:fe1f:b77b/64 scope:link up broadcast RUNNING multicast mtu:1500 M Etric:1 RX packets:43371 errors:3 dropped:0 overruns:0 frame:0 TX packets:2832 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:3458368 ( 3.2 MiB) TX bytes:347403 (339.2 KiB) interrupt:19 Base address:0x2000 eth0:0 Link encap:ethernet HWaddr 00:0c:29:1f:b7:7binet addr:192.168.1.168 bcast:192.168.1.255 mask:255.255.255.0Up broadcast RUNNING multicast mtu:1500 metric:1 interrupt:19 Base address:0x2000 lo Link encap:local lo Opback inet addr:127.0.0.1 mask:255.0.0.0 inet6 addr::: 1/128 scope:host up LOOPBACK RUNNING mtu:65536 metric:1 RX packets:9 errors:0 dropped:0 overruns:0 frame:0 TX packets:9 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:612 (612.0 b) TX bytes:612 (612.0 b) [[email protected] ~]#
Close temporary ip:ifconfig eth0:0 down
To be permanently active, copy the configuration file to eth0:0
[[email protected] ~]# Cd/etc/sysconfig/network-scripts/[[email protected] network-scripts]# CP Ifcfg-eth0 Ifcfg-eth0:0[[email protected] network-scripts]# vi ifcfg-eth0:0device=eth0:0hwaddr=00:0c:29:1f:b7 : 7btype=ethernetuuid=938bff60-0b1e-4ed3-9ff8-74eb8ba0ed57onboot=yesnm_controlled=nobootproto=staticipaddr= 192.168.1.168netmask=255.255.255.0gateway=192.168.1.1~
[Email protected] network-scripts]#/etc/init.d/network restart
4) Configure the DNS to modify:
[Email protected] network-scripts]# cat/etc/resolv.conf nameserver 8.8.8.8nameserver 202.106.0.20
Because centos6.8 above as long as/etc/sysconfig/network-scripts/ifcfg-eth0 configuration DNS1 after reboot will be synchronized to/etc/resolv.conf inside so in/etc/sysconfig/ Network-scripts/ifcfg-eth0 Configure DNS as
5) View Gateway
[[email protected] network-scripts]# route-n view Kernel IP Routing tabledestination Gateway genmask Flags Metric Ref use Iface192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0169.254.0.0 0.0.0.0 255.255.0.0 U 1002 0 0 eth00.0.0.0 192.168.1.1 0.0.0.0 UG 0 0 0 eth0
#下面的命令是临时生效的
[[email protected] network-scripts]# route del default GW 192.168.1.1 Delete Gateway
[[email protected] network-scripts]# route add default GW 192.168.1.1 adding gateway
Gateways first look at/etc/sysconfig/network/ifcfg-eth0 inside the gateway if not then find/etc/sysconfig/network under the gateway
[Email protected] ~]# Cat/etc/sysconfig/networknetworking=yeshostname=greymoustergateway=192.168.1.1[[email Protected] ~]#
Tip: If the gateway inside the/etc/sysconfig/network/ifcfg-eth0 is configured, it will take effect first
#第一生效文件
[Email protected] ~]# grep-i gate/etc/sysconfig/network-scripts/ifcfg-eth0gateway=192.168.1.1
View DNS domain name resolution
[Email protected] ~]# dig www.baidu.com
[email protected] ~]# nslookup
Linux Network check: Ping
[Email protected] ~]# traceroute www.baidu.com
Windows: Trace routes
Cmd:tracert-d www.baidu.com
Tcpdump Grab Bag:
[Email protected] ~]# host www.baidu.comwww.baidu.com is a alias for www.a.shifen.com.www.a.shifen.com have address 119.7 5.217.109www.a.shifen.com has address 119.75.218.70
Linux system basic Network configuration