ifconfig命令/hostname更改/域名重定向

ifconfig命令用于查看或更改网卡配置信息,启动或关闭网卡

安装:

[root@localhost ~]# yum -y install net-tools

使用:

[root@localhost ~]# ifconfig -a
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.234.128  netmask 255.255.255.0  broadcast 192.168.234.255
        inet6 fe80::777d:eb3e:9e03:3457  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:10:01:94  txqueuelen 1000  (Ethernet)
        RX packets 253157  bytes 67090793 (63.9 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 343338  bytes 103040732 (98.2 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

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>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 120  bytes 10496 (10.2 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 120  bytes 10496 (10.2 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

-a参数:显示所有网卡信息,如未加-a参数,只显示已激活网卡的信息

ifdown:关闭网卡

[root@localhost ~]# ifdown ens33

ifup:启动网卡

[root@localhost ~]# ifup ens33

常用于在修改了网卡配置后重启单个指定的网卡,而不需要重启网络服务影响所有网卡:

[root@localhost ~]# ifdown ens33 && ifup ens33

添加虚拟网卡:ens33:01

[root@localhost ~]# cd /etc/sysconfig/network-scripts/

[root@localhost network-scripts]# cp ifcfg-ens33 ifcfg-ens33\:01

修改虚拟网卡配置文件:

[root@localhost network-scripts]# vim ifcfg-ens33:01

修改以下内容:NAME/DEVICE/IPADDR

ifconfig命令/hostname更改/域名重定向
重启网卡:

[root@localhost ~]# ifdown ens33 && ifup ens33

虚拟网卡已在运行:

[root@localhost ~]# ifconfig -a
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.234.128  netmask 255.255.255.0  broadcast 192.168.234.255
        inet6 fe80::777d:eb3e:9e03:3457  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:10:01:94  txqueuelen 1000  (Ethernet)
        RX packets 271863  bytes 87467742 (83.4 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 349091  bytes 103525345 (98.7 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

ens33:01: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.234.129  netmask 255.255.255.0  broadcast 192.168.234.255
        ether 00:0c:29:10:01:94  txqueuelen 1000  (Ethernet)

mii-tool命令:查看网络接口状态

[root@localhost ~]# mii-tool ens33
ens33: negotiated 1000baseT-FD flow-control, link ok

*最后一列 link值为ok表示网卡已连接

ethtool命令:与mii-tool命令类似

[root@localhost ~]# ethtool ens33

*最后一行 Link detected值为yes表示网卡已连接

linux下更改hostname:

临时更改,终端重新连接后生效,系统重启后失效

[root@localhost ~]# hostname test

永久更改:

[root@test ~]# hostnamectl set-hostname linux
[root@linux ~]# cat /etc/hostname 
linux

DNS配置文件:

[root@linux ~]# cat /etc/resolv.conf 
# Generated by NetworkManager
nameserver 192.168.234.2

*该文件中的DNS配置信息来自于网卡配置文件中定义的DNS地址,可以临时更改

域名重定向文件:

[root@linux ~]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

*可以使单个或多个域名在访问时指向指定的 IP地址

[root@linux ~]# echo '192.168.234.129 www.baidu.com' >> /etc/hosts

*将访问百度时的地址指向虚拟网卡地址192.168.234.129

[root@linux ~]# ping www.baidu.com
PING www.baidu.com (192.168.234.129) 56(84) bytes of data.
64 bytes from www.baidu.com (192.168.234.129): icmp_seq=1 ttl=64 time=0.154 ms
64 bytes from www.baidu.com (192.168.234.129): icmp_seq=2 ttl=64 time=0.111 ms

*域名重定向只在本机生效

上一篇:keepalived 双机热备配置文件详解


下一篇:CentOS7 基本网络配置