linux网络相关的命令,linux网络相关命令


ifconfig查看网卡

ifconfig是在centos6中查看网卡的命令,在centos7中要安装net-tools包后才能使用?
网卡配置文件:/etc/sysconfig/network-scripts/ifcfg-ens33?
命令:ifconfig

[root@shuai-01 ~]# ifconfig
ens33: flags=4163  mtu 1500
        inet 192.168.176.135  netmask 255.255.255.0  broadcast 192.168.176.255
        inet6 fe80::16f5:8ee4:b971:e6fb  prefixlen 64  scopeid 0x20
        ether 00:0c:29:a1:0e:2c  txqueuelen 1000  (Ethernet)
        RX packets 236  bytes 23351 (22.8 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 216  bytes 25791 (25.1 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10
        loop  txqueuelen 1  (Local Loopback)
        RX packets 68  bytes 5524 (5.3 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 68  bytes 5524 (5.3 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

关闭网卡:

ifdown ens33

启动网卡:

ifup ens33

关闭网卡时,是无法远程连接的。特别是正在使用该网卡时。

想重启某个网卡:

[root@shuai-01 ~]# ifdown ens33 && ifup ens33
成功断开设备 'ens33'。
成功激活的连接(D-Bus 激活路径:/org/freedesktop/NetworkManager/ActiveConnection/1)

想重启网络服务:

service restrat network

给一个网卡设置多个ip

一个网卡是可以设置多个IP的,给一块网卡设置一个虚拟IP?
进入网卡配置文件并拷贝一份配置文件

[root@shuai-01 ~]# cd /etc/sysconfig/network-scripts/
[root@shuai-01 network-scripts]# ls
ifcfg-ens33  ifdown-ppp       ifup-ib      ifup-Team
ifcfg-lo     ifdown-routes    ifup-ippp    ifup-TeamPort
ifdown       ifdown-sit       ifup-ipv6    ifup-tunnel
ifdown-bnep  ifdown-Team      ifup-isdn    ifup-wireless
ifdown-eth   ifdown-TeamPort  ifup-plip    init.ipv6-global
ifdown-ib    ifdown-tunnel    ifup-plusb   network-functions
ifdown-ippp  ifup             ifup-post    network-functions-ipv6
ifdown-ipv6  ifup-aliases     ifup-ppp
ifdown-isdn  ifup-bnep        ifup-routes
ifdown-post  ifup-eth         ifup-sit
[root@shuai-01 network-scripts]# cp ifcfg-ens33 ifcfg-ens33:0

vi新的配置文件更改信息:NAME,DEVICE,IPADDR,GATEWAY,DNS

NAME=ens33:0
DEVICE=ens33:0
IPADDR=192.168.176.150

GATEWAY ,DNS不要

保存退出后重启网卡:

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

查看网卡的连接状态

命令:mii-tool

[root@shuai-01 network-scripts]# mii-tool ens33
ens33: negotiated 1000baseT-FD flow-control, link ok

link ok 表示连接网线?
命令:ethtool

[root@shuai-01 network-scripts]# ethtool ens33
Settings for ens33:
    Supported ports: [ TP ]
    Supported link modes:   10baseT/Half 10baseT/Full 
                            100baseT/Half 100baseT/Full 
                            1000baseT/Full 
    Supported pause frame use: No
    Supports auto-negotiation: Yes
    Advertised link modes:  10baseT/Half 10baseT/Full 
                            100baseT/Half 100baseT/Full 
                            1000baseT/Full 
    Advertised pause frame use: No
    Advertised auto-negotiation: Yes
    Speed: 1000Mb/s
    Duplex: Full
    Port: Twisted Pair
    PHYAD: 0
    Transceiver: internal
    Auto-negotiation: on
    MDI-X: off (auto)
    Supports Wake-on: d
    Wake-on: d
    Current message level: 0x00000007 (7)
                   drv probe link
    Link detected: yes

link detected : yes 表示连接网线

更改主机名

命令:hostnamectl?
命令格式:hostnamectl set-hostname 主机名

主机名的配置文件:/etc/hostname

设置dns

dns配置文件:/etc/resolv.conf

查看dns配置文件:

[root@shuai-01 network-scripts]# cat /etc/resolv.conf 
# Generated by NetworkManager
nameserver 119.29.29.29

更改dns及可以在网卡配置文件中更改,又可以在dns配置文件中更改?
在网卡配置文件中加:

DNS2=8.8.8.8

在dns配置文件中(临时):

nameserver 8.8.8.8

自定义解析域名,在本机生效,定义完后,不用进过dns解析域名。?
配置文件:/etc/hosts

添加一个解析域名:

[root@shuai-01 network-scripts]# vim /etc/hosts

添加解析域名:

192.168.172.3 www.baidu.com
193.168.176.56 www.qq.com www.hao123.com

ping:

[root@shuai-01 network-scripts]# ping www.baidu.com
PING www.baidu.com (192.168.172.3) 56(84) bytes of data.

[root@shuai-01 network-scripts]# ping www.qq.com
PING www.qq.com (193.168.176.56) 56(84) bytes of data.
  • 一个IP后可跟多个域名
  • 一行只能有一个IP 

相关内容

    暂无相关文章