ethtool命令
查询和设置网卡参数
ethtool [选项] 网卡设备名称
选项 | 含义 |
---|---|
-I: | 查询网卡的相关信息 |
-d: | 查询网卡网口注册信息 |
-r: | 重置网卡网口到自适应模式 |
-S: | 查看网卡网口首发包的统计信息 |
-s[speed 10|100|1000]: 设置网卡速率为10/100/1000M
mii-tool命令
查看管理网络接口的状态
mii-tool [选项] 网卡设备名称
选项 | 含义 |
---|---|
-V: | 显示mii-tool命令版本号 |
-v: | 显示网络接口的信息 |
-R: | 重新设置mii到开启状态 |
-r: | 重新启动自动协商模式 |
-w: | 查看网络接口连续的状态变化 |
-l: | 写入事件到系统日志 |
-A: | 指定特定的网络接口 |
-F: | 更改网络接口协商方式 |
netstat命令
数据监听及网络链接情况
netstat [选项]
选项 | 含义 |
---|---|
-a或–all: | 显示所有连线中的Socket; |
-A<网络类型>或–<网络类型>: | 列出该网络类型连线中的相关地址; |
-c或–continuous: | 持续列出网络状态; |
-C或–cache: | 显示路由器配置的快取信息; |
-e或–extend: | 显示网络其他相关信息; |
-F或–fib: | 显示FIB; |
-g或–groups: | 显示多重广播功能群组组员名单; |
-h或–help: | 在线帮助; |
-i或–interfaces: | 显示网络界面信息表单; |
-l或–listening: | 显示监控中的服务器的Socket; |
-M或–masquerade: | 显示伪装的网络连线; |
-n或–numeric: | 直接使用ip地址,而不通过域名服务器; |
-N或–netlink或–symbolic: | 显示网络硬件外围设备的符号连接名称; |
-o或–timers: | 显示计时器; |
-p或–programs: | 显示正在使用Socket的程序识别码和程序名称; |
-r或–route: | 显示Routing Table; |
-s或–statistice: | 显示网络工作信息统计表; |
-t或–tcp: | 显示TCP传输协议的连线状况; |
-u或–udp: | 显示UDP传输协议的连线状况; |
-v或–verbose: | 显示指令执行过程; |
-V或–version: | 显示版本信息; |
-w或–raw: | 显示RAW传输协议的连线状况; |
-x或–unix: | 此参数的效果和指定"-A unix"参数相同; |
–ip或–inet: | 此参数的效果和指定"-A inet"参数相同。 |
例子
#列出所有端口情况
[root@xiesshavip002 ~]# netstat -a # 列出所有端口
[root@xiesshavip002 ~]# netstat -at # 列出所有TCP端口
[root@xiesshavip002 ~]# netstat -au # 列出所有UDP端口
#列出所有处于监听状态的 Sockets
[root@xiesshavip002 ~]# netstat -l # 只显示监听端口
[root@xiesshavip002 ~]# netstat -lt # 显示监听TCP端口
[root@xiesshavip002 ~]# netstat -lu # 显示监听UDP端口
[root@xiesshavip002 ~]# netstat -lx # 显示监听UNIX端口
#显示每个协议的统计信息
[root@xiesshavip002 ~]# netstat -s # 显示所有端口的统计信息
[root@xiesshavip002 ~]# netstat -st # 显示所有TCP的统计信息
[root@xiesshavip002 ~]# netstat -su # 显示所有UDP的统计信息
#显示 PID 和进程名称
[root@xiesshavip002 ~]# netstat -p
#显示核心路由信息
[root@xiesshavip002 ~]# netstat -r
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
default gateway 0.0.0.0 UG 0 0 0 eth0
192.168.130.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
[root@xiesshavip002 ~]# netstat -rn # 显示数字格式,不查询主机名称
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
0.0.0.0 192.168.130.1 0.0.0.0 UG 0 0 0 eth0
192.168.130.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
[root@xiesshavip002 ~]#
#查看端口和服务
[root@xiesshavip002 ~]# netstat -antp | grep ssh
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 734/sshd
tcp 0 52 192.168.130.20:22 119.129.118.189:58737 ESTABLISHED 1846/sshd: root@pts
tcp6 0 0 :::22 :::* LISTEN 734/sshd
[root@xiesshavip002 ~]# netstat -antp | grep 22
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 734/sshd
tcp 0 52 192.168.130.20:22 119.129.118.189:58737 ESTABLISHED 1846/sshd: root@pts
tcp6 0 0 :::22 :::* LISTEN 734/sshd
[root@xiesshavip002 ~]#
netstat --help
[root@xiesshavip002 ~]# netstat --help
usage: netstat [-vWeenNcCF] [<Af>] -r netstat {-V|--version|-h|--help}
netstat [-vWnNcaeol] [<Socket> ...]
netstat { [-vWeenNac] -I[<Iface>] | [-veenNac] -i | [-cnNe] -M | -s [-6tuw] } [delay]
-r, --route display routing table
-I, --interfaces=<Iface> display interface table for <Iface>
-i, --interfaces display interface table
-g, --groups display multicast group memberships
-s, --statistics display networking statistics (like SNMP)
-M, --masquerade display masqueraded connections
-v, --verbose be verbose
-W, --wide don't truncate IP addresses
-n, --numeric don't resolve names
--numeric-hosts don't resolve host names
--numeric-ports don't resolve port names
--numeric-users don't resolve user names
-N, --symbolic resolve hardware names
-e, --extend display other/more information
-p, --programs display PID/Program name for sockets
-o, --timers display timers
-c, --continuous continuous listing
-l, --listening display listening server sockets
-a, --all display all sockets (default: connected)
-F, --fib display Forwarding Information Base (default)
-C, --cache display routing cache instead of FIB
-Z, --context display SELinux security context for sockets
<Socket>={-t|--tcp} {-u|--udp} {-U|--udplite} {-w|--raw} {-x|--unix}
--ax25 --ipx --netrom
<AF>=Use '-6|-4' or '-A <af>' or '--<af>'; default: inet
List of possible address families (which support routing):
inet (DARPA Internet) inet6 (IPv6) ax25 (AMPR AX.25)
netrom (AMPR NET/ROM) ipx (Novell IPX) ddp (Appletalk DDP)
x25 (CCITT X.25)
[root@xiesshavip002 ~]#
chkconfig命令
Linux chkconfig命令用于检查,设置系统的各种服务。
这是Red Hat公司遵循GPL规则所开发的程序,它可查询操作系统在每一个执行等级中会执行哪些系统服务,其中包括各类常驻服务。
语法
chkconfig [--add][--del][--list][系统服务] 或 chkconfig [--level <等级代号>][系统服务][on/off/reset]
参数:
–add 增加所指定的系统服务,让chkconfig指令得以管理它,并同时在系统启动的叙述文件内增加相关数据。
–del 删除所指定的系统服务,不再由chkconfig指令管理,并同时在系统启动的叙述文件内删除相关数据。
–level<等级代号> 指定读系统服务要在哪一个执行等级中开启或关毕。
实例
列出chkconfig所知道的所有命令。
chkconfig -list
#开启服务
chkconfig telnet on //开启Telnet服务
chkconfig --list //列出chkconfig所知道的所有的服务的情况
#关闭服务
chkconfig telnet off //关闭Telnet服务
chkconfig -list //列出chkconfig所知道的所有的服务的情况
nslookup命令
nslookup命令用于查询DNS的记录,查看域名解析是否正常,在网络故障的时候用来诊断网络问题。 nslookup的用法相对来说还是蛮简单的,主要是下面的几个用法。
1 直接查询
这个可能大家用到最多,查询一个域名的A记录。
nslookup domain [dns-server]
如果没指定dns-server,用系统默认的dns服务器。下面是一个例子:
[root@localhost ~]# nslookup baidu.com
Server: 10.30.7.177
Address: 10.30.7.177#53
Non-authoritative answer:
Name: baidu.com
Address: 123.125.114.144
Name: baidu.com
Address: 111.13.101.208
Name: baidu.com
Address: 180.149.132.47
Name: baidu.com
Address: 220.181.57.217
2 查询其他记录
直接查询返回的是A记录,我们可以指定参数,查询其他记录,比如AAAA、MX等。
nslookup -qt=type domain [dns-server]
其中,type可以是以下这些类型:
类型 | 含义 |
---|---|
A | 地址记录 |
AAAA | 地址记录 |
AFSDB Andrew | 文件系统数据库服务器记录 |
ATMA ATM | 地址记录 |
CNAME | 别名记录 |
HINFO | 硬件配置记录,包括CPU、操作系统信息 |
ISDN | 域名对应的ISDN号码 MB 存放指定邮箱的服务器 MG 邮件组记录 |
MINFO | 邮件组和邮箱的信息记录 |
MR | 改名的邮箱记录 |
MX | 邮件服务器记录 |
NS | 名字服务器记录 |
PTR | 反向记录 |
RP | 负责人记录 |
RT | 路由穿透记录 SRV TCP服务器信息记录 |
TXT | 域名对应的文本信息 |
X25 | 域名对应的X.25地址记录 |
例如:
[root@localhost ~]# nslookup -qt=mx baidu.com 8.8.8.8
*** Invalid option: qt=mx
Server: 8.8.8.8
Address: 8.8.8.8#53
Non-authoritative answer:
Name: baidu.com
Address: 111.13.101.208
Name: baidu.com
Address: 123.125.114.144
Name: baidu.com
Address: 180.149.132.47
Name: baidu.com
Address: 220.181.57.217
3 查询更具体的信息
查询语法:
nslookup –d [其他参数] domain [dns-server]
常用网络配置文件
/etc/nsswitch.conf
文件功能:名称服务器交换配置(/etc/nsswitch.conf)文件
[cwx@localhost ~]$ vim /etc/nsswitch.conf
# Generated by authselect on Mon Dec 14 20:56:00 2020
# Do not modify this file manually.
# If you want to make changes to nsswitch.conf please modify
# /etc/authselect/user-nsswitch.conf and run 'authselect apply-changes'.
#
# Note that your changes may not be applied as they may be
# overwritten by selected profile. Maps set in the authselect
# profile takes always precendence and overwrites the same maps
# set in the user file. Only maps that are not set by the profile
# are applied from the user file.
#
# For example, if the profile sets:
# passwd: sss files
# and /etc/authselect/user-nsswitch.conf contains:
# passwd: files
# hosts: files dns
# the resulting generated nsswitch.conf will be:
# passwd: sss files # from profile
# hosts: files dns # from user file
passwd: sss files systemd
group: sss files systemd
netgroup: sss files
automount: sss files
services: sss files
# Included from /etc/authselect/user-nsswitch.conf
#
# /etc/nsswitch.conf
#
# An example Name Service Switch config file. This file should be
# sorted with the most-used services at the beginning.
#
# The entry '[NOTFOUND=return]' means that the search for an
# entry should stop if the search in the previous entry turned
# up nothing. Note that if the search failed due to some other reason
# (like no NIS server responding) then the search continues with the
# next entry.
#
# Valid entries include:
#
# nisplus Use NIS+ (NIS version 3)
# nis Use NIS (NIS version 2), also called YP
# dns Use DNS (Domain Name Service)
# files Use the local files in /etc
# db Use the pre-processed /var/db files
# compat Use /etc files plus *_compat pseudo-databases
# hesiod Use Hesiod (DNS) for user lookups
# sss Use sssd (System Security Services Daemon)
# [NOTFOUND=return] Stop searching if not found so far
#
# 'sssd' performs its own 'files'-based caching, so it should
# generally come before 'files'.
# To use 'db', install the nss_db package, and put the 'db' in front
# of 'files' for entries you want to be looked up first in the
# databases, like this:
#
# passwd: db files
# shadow: db files
# group: db files
shadow: files sss
hosts: files dns myhostname
bootparams: files
ethers: files
netmasks: files
networks: files
protocols: files
rpc: files
publickey: files
aliases: files
/etc/services
文件功能:网络配置文件(/etc/services)文件
[cwx@localhost ~]$ vim /etc/services
常见:http: 80 pop3: 110 ssh: 22 ftp:20/21
/etc/resolv.conf
文件功能:网络配置文件(/etc/resolv.conf)文件
[cwx@localhost ~]$ vim /etc/resolv.conf
# Generated by NetworkManager
search localdomain
nameserver 192.168.45.2
/etc/sysconfig/network
文件功能:主要用于设置Linux操作系统主机名及系统启动时是否加载网卡信息
[cwx@localhost ~]$ vim /etc/sysconfig/network-scripts/ifcfg-ens33
TYPE="Ethernet" #网卡类型(通常是Ethemet以太网)
PROXY_METHOD="none" #代理方式:为关闭状态
BROWSER_ONLY="no" #只是浏览器:否
BOOTPROTO="static" #网卡的引导协议【static:静态IP dhcp:动态IP none:不指定,不指定容易出现各种各样的网络受限】
DEFROUTE="yes" #默认路由
IPV4_FAILURE_FATAL="no" #是否开启IPV4致命错误检测
IPV6INIT="yes" #IPV6是否自动初始化:是(现在还未用到IPV6,不会有任何影响)
IPV6_AUTOCONF="yes" #IPV6是否自动配置:是(现在还未用到IPV6,不会有任何影响)
IPV6_DEFROUTE="yes" #IPV6是否可以为默认路由:是(现在还未用到IPV6,不会有任何影响)
IPV6_FAILURE_FATAL="no" #是否开启IPV6致命错误检测
IPV6_ADDR_GEN_MODE="stable-privacy" #IPV6地址生成模型
NAME="ens33" #网卡物理设备名称
UUID="ab60d501-535b-49f5-a76b-3336a4120f64"#通用唯一识别码,每一个网卡都会有,不能重复,否则两台linux机器只有一台可上网
DEVICE="ens33" #网卡设备名称,必须和‘NAME’值一样
ONBOOT="yes" #是否开机启动,要想网卡开机就启动或通过 `systemctl restart network`控制网卡,必须设置为 `yes`
IPADDR=192.168.137.129 # 本机IP
NAME="enp2s0" #网卡设备名称;
DEVICE="enp2s0" #网卡设备名称;
ONBOOT=yes #是否启用该设备;
BOOTPROTO=none #协议类型:手动(none/static)、自动(dhcp);
IPADDR=192.168.80.62 #网络ip地址
PREFIX=24 #子网掩码
GATEWAY=198.168.112.254 #网关地址
注:ssh是目前较可靠,专为远程登录会话和其他网络服务,提供安全性的协议