Linux 网络相关

功能 语法
启动网卡 ifup 网卡名
关闭网卡 ifdown 网卡名
重启单个网卡 ifdown ens33 && ifup ens33
查看网卡是否连接 mii-tool 网卡名
查看主机名 hostname
更改主机名(重新登录即可永久生效) hostnamectl set-hostname 主机名
主机名的配置文件 /etc/hostname
网卡配置文件 /etc/sysconfig/network-scripts/
DNS 配置文件 (可在网卡配置文件中更改) /etc/resolv.conf
在本机更改 ping 的域名 vi /etc/hosts 进入之后 ip+ 域名(可一个 ip 多个域名)
  • 增加虚拟网卡(增加一个 ip)

1. 进入网卡配置文件,cp 一个网卡

[root@localhost ~]# cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# ls
ifcfg-ens33  ifdown-ippp    ifdown-sit       ifup-bnep  ifup-plip    ifup-Team          network-functions-ipv6
ifcfg-lo     ifdown-ipv6    ifdown-Team      ifup-eth   ifup-plusb   ifup-TeamPort
ifdown       ifdown-isdn    ifdown-TeamPort  ifup-ib    ifup-post    ifup-tunnel
ifdown-bnep  ifdown-post    ifdown-tunnel    ifup-ippp  ifup-ppp     ifup-wireless
ifdown-eth   ifdown-ppp     ifup             ifup-ipv6  ifup-routes  init.ipv6-global
ifdown-ib    ifdown-routes  ifup-aliases     ifup-isdn  ifup-sit     network-functions
[root@localhost network-scripts]# cp ifcfg-ens33 ifcfg-ens33\:0     //这里的\是指脱义

2. 进入虚拟网卡,更改配置文件

[root@localhost network-scripts]# vi ifcfg-ens33:0
说明:
需要更改
NAME=ens33:0
DEVICE=ens33:0
IPADDR=192.168.152.150
DNS1和GATEWAY可以不要

3. 重启网卡

[root@localhost network-scripts]# ifdown ens33 && ifup ens33

4. 查看网卡

[root@localhost network-scripts]# ifconfig 
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.152.128  netmask 255.255.255.0  broadcast 192.168.152.255
        inet6 fe80::50e7:255d:8ff7:2d3d  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:e5:64:9c  txqueuelen 1000  (Ethernet)
        RX packets 4359  bytes 4527748 (4.3 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 1491  bytes 139638 (136.3 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

ens33:0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.152.150  netmask 255.255.255.0  broadcast 192.168.152.255
        ether 00:0c:29:e5:64:9c  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>
        loop  txqueuelen 1  (Local Loopback)
        RX packets 80  bytes 6940 (6.7 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 80  bytes 6940 (6.7 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0