Linux命令-网络命令
时间:2020-02-23 14:39:27 来源:igfitidea点击:
以下是Linux中一些重要的网络命令。
ping
此命令将回显请求发送到域以测试网络连接。
在以下示例中,我们将回显请求发送到google.com。
$ping google.com PING google.com (172.217.163.46): 56 data bytes 64 bytes from 172.217.163.46: icmp_seq=0 ttl=57 time=37.225 ms 64 bytes from 172.217.163.46: icmp_seq=1 ttl=57 time=35.177 ms 64 bytes from 172.217.163.46: icmp_seq=2 ttl=57 time=34.801 ms ^C --- google.com ping statistics -- 3 packets transmitted, 3 packets received, 0.0% packet loss round-trip min/avg/max/stddev = 34.801/35.734/37.225/1.065 ms
除非您按Ctrl + C退出,否则以上命令将保持打印响应。
ping 域-c N
这会将回送请求发送N次到域。
在以下示例中,我们向google.com发送了3次回显请求。
$ping google.com -c 3 PING google.com (172.217.163.46): 56 data bytes 64 bytes from 172.217.163.46: icmp_seq=0 ttl=57 time=34.536 ms 64 bytes from 172.217.163.46: icmp_seq=1 ttl=57 time=34.687 ms 64 bytes from 172.217.163.46: icmp_seq=2 ttl=57 time=36.030 ms --- google.com ping statistics -- 3 packets transmitted, 3 packets received, 0.0% packet loss round-trip min/avg/max/stddev = 34.536/35.084/36.030/0.672 ms
ifconfig
该命令用于配置网络接口。
ifconfig -a
这将列出当前可用的所有网络接口,即使其中一些已关闭。
$ifconfig -a
ifconfig eth0
这将显示eth0以太网端口IP地址和其他详细信息。
$ifconfig -a
w
此命令将打印有关域的WHOIS信息。
在以下示例中,我们将获取google.com的WHOIS信息。
$whois google.com Domain Name: GOOGLE.COM Registry Domain ID: 2138514_DOMAIN_COM-VRSN Registrar WHOIS Server: whois.markmonitor.com Registrar URL: http://www.markmonitor.com Updated Date: 2016-02-21T18:36:40Z Creation Date: 1997-09-15T04:00:00Z Registry Expiry Date: 2017-09-14T04:00:00Z ... ... ...
host
此命令将查找给定域的DNS(域名系统)。
在以下示例中,我们正在检查google.com域的DNS信息。
$host google.com google.com has address 172.217.163.46 google.com has IPv6 address 2404:6800:4007:80b::200e google.com mail is handled by 30 alt2.aspmx.l.google.com. google.com mail is handled by 50 alt4.aspmx.l.google.com. google.com mail is handled by 20 alt1.aspmx.l.google.com. google.com mail is handled by 10 aspmx.l.google.com. google.com mail is handled by 40 alt3.aspmx.l.google.com.
dig
此命令为我们获取给定域名的DNS名称服务器信息。
DIG =域信息收集器
在以下示例中,我们正在获取google.com的名称服务器信息。
$dig google.com ; <<>> DiG 9.11.3-1ubuntu1-Ubuntu <<>> google.com ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 27551 ;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1 ;; OPT PSEUDOSECTION: ; EDNS: version: 0, flags:; udp: 65494 ;; QUESTION SECTION: ;google.com. IN A ;; ANSWER SECTION: google.com. 188 IN A 172.217.161.14 ;; Query time: 63 msec ;; SERVER: 127.0.0.53#53(127.0.0.53) ;; WHEN: Mon Jan 01 01:01:01 IST 2016 ;; MSG SIZE rcvd: 55
hostname -i
这将查找本地IP地址。
在下面的示例中,当我使用笔记本电脑时,我将本地IP地址设为127.0.1.1。
$hostname -i 127.0.1.1
netstat
此命令将列出所有活动的监听端口。
在以下示例中,我们列出了所有活动端口。
$netstat -tupl (Not all processes could be identified, non-owned process info will not be shown, you would have to be root to see it all.) Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 localhost:domain 0.0.0.0:* LISTEN - tcp 0 0 localhost:ipp 0.0.0.0:* LISTEN - tcp6 0 0 ip6-localhost:ipp [::]:* LISTEN - udp 39936 0 localhost:domain 0.0.0.0:* - udp 2176 0 0.0.0.0:bootpc 0.0.0.0:* - udp 0 0 0.0.0.0:45148 0.0.0.0:* - udp 51456 0 0.0.0.0:mdns 0.0.0.0:* - udp 0 0 0.0.0.0:ipp 0.0.0.0:* - udp6 23040 0 [::]:mdns [::]:* - udp6 0 0 [::]:38193 [::]:*
nslookup
此命令查询Internet名称服务器并将域名解析为IP地址。
在以下示例中,我们获取了google.com的IP地址。
$nslookup google.com Server: 127.0.0.53 Address: 127.0.0.53#53 Non-authoritative answer: Name: google.com Address: 172.217.161.14 Name: google.com Address: 2404:6800:4002:807::200e
wget
此命令用于从Web下载文件。
在以下示例中,我们从其GitHub存储库下载jQuery。
$wget https://github.com/jquery/jquery/archive/3.3.1.tar.gz