View Host Name
hostname command: To view or set the current host name
Modify the host name
hostnamectl set-hostname new hostname command: modify the current host name
Directly modify the configuration file "/ etc / sysconfig / network" in
View network interface information
ifconfig [network interface name] command: Specifies an information network interfaces, all interface information does not specify the interface is displayed.
Here to explain a few important parameters:
inet 192.168.52.131 //IP地址
netmask 255.255.255.0 //子网掩码
broadcast 192.168.52.255 //广播地址
inet6 fe80::8629:c3e2:139c:884a //ipv6地址
ether 00:0c:29:7a:41:33 //MAC地址
Set the network parameters of ways:
Temporary configuration: ifconfig network interface name IP address command ---------- use a command to adjust the network parameters
can be quickly and directly modify network parameters, generally suitable for use in the process of debugging the network, changes made to the system will reboot disappear.
Fixed: after modifying network parameters by modifying the configuration file, suitable for use when the server is set fixed parameters, need to restart the network services or reboot the system to take effect.
Disable and activate the card
Disable network card: ifconfig network interface down
[root@localhost ~]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.52.131 netmask 255.255.255.0 broadcast 192.168.52.255
inet6 fe80::8629:c3e2:139c:884a prefixlen 64 scopeid 0x20<link>
.................................. //省略部分内容
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
.................................. //省略部分内容
virbr0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255
ether 52:54:00:31:df:fc txqueuelen 1000 (Ethernet)
.................................. //省略部分内容
[root@localhost ~]# ifconfig ens33 down
[root@localhost ~]# ifconfig
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
.................................. //省略部分内容
virbr0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255
ether 52:54:00:31:df:fc txqueuelen 1000 (Ethernet)
.................................. //省略部分内容
Enable NIC: ifconfig network interface up
[root@localhost ~]# ifconfig
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
.................................. //省略部分内容
virbr0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255
ether 52:54:00:31:df:fc txqueuelen 1000 (Ethernet)
.................................. //省略部分内容
[root@localhost ~]# ifconfig ens33 up
[root@localhost ~]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.52.131 netmask 255.255.255.0 broadcast 192.168.52.255
inet6 fe80::8629:c3e2:139c:884a prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:7a:41:33 txqueuelen 1000 (Ethernet)
.................................. //省略部分内容
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
.................................. //省略部分内容
virbr0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255
ether 52:54:00:31:df:fc txqueuelen 1000 (Ethernet)
Enable the network interface can also use the command "ifup network interface" to close the network interface can also use the command "ifdown network interface." Network Service Restart general command "service network restart" or "systemctl restart network".
Set up a virtual network interface:
ifconfig network interface: Serial IP address Note: Close the virtual network interface directly deleted, can not be re-opened.
[root@localhost ~]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.52.131 netmask 255.255.255.0 broadcast 192.168.52.255
inet6 fe80::8629:c3e2:139c:884a prefixlen 64 scopeid 0x20<link>
.................................. //省略部分内容
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
.................................. //省略部分内容
virbr0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255
ether 52:54:00:31:df:fc txqueuelen 1000 (Ethernet)
.................................. //省略部分内容
[root@localhost ~]# ifconfig ens33:0 192.168.100.100
[root@localhost ~]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.52.131 netmask 255.255.255.0 broadcast 192.168.52.255
inet6 fe80::8629:c3e2:139c:884a prefixlen 64 scopeid 0x20<link>
.................................. //省略部分内容
ens33:0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.100.100 netmask 255.255.255.0 broadcast 192.168.100.255
ether 00:0c:29:7a:41:33 txqueuelen 1000 (Ethernet)
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
.................................. //省略部分内容
virbr0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255
ether 52:54:00:31:df:fc txqueuelen 1000 (Ethernet)
.................................. //省略部分内容
View network connections
netstat command: View the status of the network connection system, routing tables, interface statistics and other information
Common options:
-a: 列出所有当前的连接
-n: 禁用域名解析功能
-p: 查看进程信息
-t: 列出 TCP 协议的连接
-u: 列出 UDP 协议的连接
-r: 打印内核路由信息
View the routing table entries
route command: View or set the host routing table information, with "netstat -r" similar
In Linux6 version "0.0.0.0" will be displayed as "*" form, only adding "-n" option in order to "0.0.0.0" is displayed.
Set the routing record
添加到指定网段的路由记录:
route add -net 网段地址 gw IP地址
删除到指定网段的路由记录:
route del -net 网段地址
向路由表中添加默认网关记录:
route add default gw IP地址
删除路由表中的默认网关记录:
route del default gw IP地址
测试网络连接
ping命令:测试网络连通性,按[Ctrl+C]终止测试
跟踪数据包
traceroute 目标主机地址 命令:测试从当前主机到目的主机之间经过的网络节点
当我们的网络不能够正常通讯的时候,可以用traceroute命令,看一下是那个节点出了问题。
域名解析
nslookup 目标主机地址 [DNS服务器地址] 命令:测试DNS域名解析
DNS地址更改
在配置文件“/etc/resolv.conf”里直接修改即可
本地主机映射文件
“/etc/hosts”保存主机名与IP地址的映射记录
默认情况下,系统首先从hosts文件查找解析记录。找不到的情况下才会通过DNS服务器解析,hosts文件能够加快访问的速度,但是只对当前主机有效。
scp命令远程复制
将本地文件同步到远程服务器
scp 本地同步文件路径 用户@IP:远程服务器文件路径
我们在host01主机的“/etc/hosts”文件中添加两个DNS映射记录,然后在host01主机上通过scp命令,将它同步到host02主机上。
The remote server file synchronization to local
scp user @IP: synchronous remote server file path of the local file path
we add two DNS mapping records in host02 host of "/ etc / hosts" file, and then host it on host01 from host02 synchronization over the host.