First, view 1.ip A//Simply view the network card IP information for the current host
1: lo(本地回环网卡): <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo inet6 ::1/128 scope host valid_lft forever preferred_lft forever2: eth0(eth代表Ethernet、0表示第一块网卡): <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP(网卡工作正常,DOWN代表网卡未启用或未配置IP,UNKNOWN代表网卡异常或网线问题、IP地址配置错误) qlen 1000 link/ether 00:0c:29:77:21:e6(网卡的MAC地址) brd ff:ff:ff:ff:ff:ff(网卡的MAC广播地址) inet 192.168.10.118/24(网卡的IP地址和子网掩码) brd 192.168.10.255(当前IP的广播地址) scope global eth0 inet6 fe80::20c:29ff:fe77:21e6/64(网卡的IPv6地址) scope link valid_lft forever preferred_lft forever
2.ifconfig//Detailed view of network card IP information for the current host
eth0 Link encap:ethernet HWaddr 00:0c:29:77:21:e6 (the MAC address of the network card) inet addr:192.168.10.118 (IP address of the network card) Bcas T:192.168.10.255 (the broadcast address of the network card) mask:255.255.255.0 (subnet mask of the network card) Inet6 ADDR:FE80::20C:29FF:FE77:21E6/64 (the IPV6 address of the network card) scope:l Ink up Broadcast RUNNING multicast mtu:1500 metric:1 RX packets:27592 errors:0 dropped:0 overruns:0 fr ame:0 (number of packets sent, multiple sent) TX packets:2250 errors:0 dropped:0 overruns:0 carrier:0 (number of packets received, less received) collisions:0 T xqueuelen:1000 RX bytes:18178026 (17.3 MiB) (total size of sending packets) TX bytes:265125 (258.9 KiB) (total size of received packets) Lo (local loopback nic) Link encap:local Loopback 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:28 errors:0 dropped:0 overruns:0 frame:0 TX packets:28 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:2240 (2.1 KiB) TX bytes:2240 (2.1 KiB)
3.ip r//view routing information (default behavior defaults gateway address)
192.168.10.0/24 dev eth0 proto kernel scope link src 192.168.10.118 169.254.0.0/16 dev eth0 scope link metric 1002 default via 192.168.10.1 dev eth0 //eth0网卡的网关地址为192.168.10.1
4.route-n//View routing information (verbose)
Kernel IP routing tableDestination Gateway Genmask Flags Metric Ref Use Iface(目标网段) (网关地址) (目标网段子网掩码)(路由状态U代表UP、G代表Gateway、H代表Host) (出口网卡)192.168.10.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.10.1 0.0.0.0 UG 0 0 0 eth0
5.cat/etc/resolv.conf//View DNS information
nameserver 192.168.3.5
6.hostname//view current host name (Identity host role) II. configuration 1. Temporary configuration (effective immediately, no restart required.) Lost after reboot) IP address
(1)ip a add [IP地址/子网掩码] dev 网卡设备名称 //给指定网卡新增临时IP地址
Cases:
[[Email protected] ~]# IP a add 192.168.10.223/24 dev eth0//Configure temporary IP address for eth0 NIC
(2)ip a del [IP地址/子网掩码] dev 网卡设备 //临时删除指定网卡的指定IP地址
Cases:
[[Email protected] ~]# ip a del 192.168.10.233/24 dev eth0//temporarily delete eth0 address of network card
(3)ifconfig 网卡设备 [IP地址/子网掩码] //替换指定网卡IP地址
Cases:
[[email protected] ~]# ifconfig eth0 192.168.10.233/24//Replace the NIC's original IP address
Gateway Address
(4)route add default gw [网关地址] dev [网卡设备名称] //为指定网卡临时设置网关地址
Cases:
[[email protected] ~]# route add default GW 192.168.10.1 dev eth0//set eth0 NIC Gateway to 192.168.10.1
(5)route del default gw [网关地址] dev [网卡设备] //临时删除指定网卡的默认地址
Cases:
[[email protected] ~]# route del default GW 192.168.10.1 dev eth0//Temporary delete eth0 NIC gateway address
DNS Address
(6)vim /etc/resolv.conf //配置当前主机DNS服务器地址nameserver [DNS地址]
Note: General nameserver configuration Two, the system reads from the top down. Switch to the next DNS server only if the previous one does not work.
Host Name
(7)hostname 主机名 && bash //临时设置主机名
Cases:
[[email protected] ~]# hostname www.hiahia.org && bash//temporarily set current host name www.hiahia.org
2. Permanent configuration (takes effect after reboot, still exists after reboot) IP address
(1)vim /etc/sysconfig/network-scripts/ifcfg-eth0 //编辑网卡配置文件DEVICE=eth0 //网卡设备TYPE=Ethernet //网卡类型ONBOOT=yes //开机自启NM_CONTROLLED=no //禁用networkmanagerBOOTPROTO=static //网卡地址为静态IPIPADDR=192.168.10.123 //网卡IPNETMASK=255.255.255.0 //网卡子网掩码GATEWAY=192.168.10.1 //网卡网关DNS1=192.168.3.5 //网卡首选DNSDNS2=114.114.114.114 //网卡备用DNS
(2)reboot | service network restart | /etc/init.d/network restart //重启或重启服务生效
Host Name
(1)vim /etc/sysconfig/network //修改当前系统主机名配置文件NETWORKING=yesHOSTNAME=www.hiahia.org //当前系统的主机名
(2)reboot //只能重启生效
Linux Network configuration