linux下的网络命令非常强大,这里根据教材需要,列出来常用的网络命令和场景实例,供参考。
一、命令列表:
以上的命令都是在tcp/ip层之间操作。一些比较详细的需要研究对应的tcp/ip协议。 来自 <https://itsfoss.com/basic-linux-networking-commands/#essential-networking-commands-in-linux> TCP/IP protocol stack vs the OSI reference model |
二、包运行环境
请注意,并非所有的命令都会预先安装。Ubuntu/Centos的环境我事先都需要先安装了。对于其他发行版,请使用您的包管理器。 |
我这里适用了ubuntu、centos 和kali版本(未完全)做验证。分别对应的版本£§¤¥ 其中ubuntu的版本和内核如下: £1 £2 Kali 的版本和内核如下:§1 §2 centos的版本和内核如下:¤1 |
三、工具包运行实例
Note: Both net-tools and iproute2 command are available on most Linux distributions. However, it is recommended to use iproute2 tools due to their flexibility and speed.
Although net-tools is deemed as outdated, it is still widely used by legacy scripts and configurations.
£1为例
1、主机信息相关的cmds | |||||
IP ip [options] object [command]
ip addr [subcommand] The available subcommands on the object are:
ip monitor ip link [subcommand] [options] [interfaces] The subcommands enable the following actions:
ip route [subcommand] [options] [destination] The following actions are available as subcommands:
| |||||
Nslookup nslookup <domainName>
| |||||
Dig dig [options] [domain] [record type] [DNS server] The components of the command are:
All parameters are optional. The command shows the default DNS resolver information and query statistics without additional options.
| |||||
Ping ping [options] [hostname/IP] ping -c 5 google.com | |||||
Uname | |||||
Host host [options] [hostname/IP] The various [options] control the command's behavior, such as the query type or the start of authority (SOA) for the provided domain.
| |||||
Ifconfig ifconfig [interface] [options]
| |||||
Nslookup nslookup [domain] [DNS server]
| |||||
2、网络连接相关cmds | ||||
Scp 选项非常多,简单的如下: scp [OPTION] [user@]SRC_HOST:]file1 [user@]DEST_HOST:]file2 1、从本地拷贝到远程: scp local_file remote_username@remote_ip:remote_folder或者 scp local_file remote_username@remote_ip:remote_file或者 scp local_file remote_ip:remote_folder或者 scp local_file remote_ip:remote_file 如果复制目录,需要-r参数:scp -r 2、从远程拷贝到本地: 只要把本地复制到远程的命令的后面2个参数调换顺序即可。 若远程防火墙有为scp指定了端口号,需要使用-p参数:scp -p 比如scp命令使用端口号6389:scp -p 6389 注意:使用scp命令要确保使用的用户具有远程服务器文件对应的权限,否则无法起作用。 | ||||
Rsync 1、同步本地不同路径下的两个目录
2、使用-a选项表示存档模式。
3、将文件在本地目录和远程目录之间的同步 rsync允许在本地和远程系统之间同步文件/目录,前提是本地和远程系统都要安装rsync才行。
| ||||
Ss ss [options] [filter]
| ||||
Route route [options] [subcommand] [arguments] It contains the following components:
|
3、网络监控相关cmds | |||
Netstat netstat [options]
| |||
Netcat | |||
Tcpdump tcpdump命令是一个数据包嗅探器和网络安全工具,用于捕获实时网络数据包信息。使用命令可以分析流量、排除问题和监视网络安全。 tcpdump [options] [filter]
| |||
Traceroute traceroute [options] [hostname/IP]
| |||
Iftop iftop命令是一个网络监视实用程序。使用命令可真实的查看网络连接和带宽使用情况。 iftop [options]
| |||
Tracepath tracepath [options] [hostname/IP] | |||
Mtr mtr命令(my traceroute)是一个诊断工具,它结合了ping和traceroute命令中的元素。该命令发送对网络质量的实时洞察,使其成为解决高延迟和数据包丢失问题的绝佳工具。 mtr [options] [hostname/IP]
| |||
Nmap (这个有必要单独列一个章节深究) nmap is a network scanning tool for network exploration and security auditing. It allows you to discover hosts on a network, identify open ports, gather information about services running on those ports, and even detect security vulnerabilities.
| |||
4、其他方面cmds | |
Curl or wget wget [options] [URL] curl [options] [URL] To download a file using the wget command, use the following format: 使用wget下载文件命令如下: wget -O [file name] [URL] Alternatively, to use curl to achieve the same task, run: 或者,要使用curl来实现相同的任务,请运行: curl -o [file name] [URL] The file downloads from the specified URL and saves the contents to the provided file name. 文件从指定的URL下载并将内容保存到提供的文件名。 | |
Whois whois [options] [query] | |
五、linux下一些troubleshooting的技巧Troubleshooting Network Issues
|