mirror of
https://github.com/LCTT/TranslateProject.git
synced 2025-03-03 01:10:13 +08:00
commit
705f83020d
@ -1,147 +0,0 @@
|
||||
Translating by bianjp
|
||||
|
||||
Basic Linux Networking Commands You Should Know
|
||||
==================================================
|
||||
|
||||

|
||||
|
||||
Brief: A collection of most important and yet basic Linux networking commands an aspiring Linux SysAdmin and Linux enthusiasts must know.
|
||||
|
||||
It’s not every day at It’s FOSS that we talk about the “command line side” of Linux. Basically, I focus more on the desktop side of Linux. But as some of you readers pointed out in the internal survey (exclusive for It’s FOSS newsletter subscribers), that you would like to learn some command line tricks as well. Cheat sheets were also liked and encouraged by most readers.
|
||||
|
||||
For this purpose, I have compiled a list of the basic networking commands in Linux. It’s not a tutorial that teaches you how to use these commands, rather, it’s a collection of commands and their short explanation. So if you already have some experience with these commands, you can use it for quickly remembering the commands.
|
||||
|
||||
You can bookmark this page for quick reference or even download all the commands in PDF for offline access.
|
||||
|
||||
I had this list of Linux networking commands when I was a student of Communication System Engineering. It helped me to get the top score in Computer Networks course. I hope it helps you in the same way.
|
||||
|
||||
>Exclusive bonus: [Download Linux Networking Commands Cheat Sheet][1] for future reference. You can print it or save it for offline viewing.
|
||||
|
||||
### List of basic networking commands in Linux
|
||||
|
||||
I used FreeBSD in the computer networking course but the UNIX commands should work the same in Linux also.
|
||||
|
||||
#### Connectivity:
|
||||
|
||||
- ping <host> —- sends an ICMP echo message (one packet) to a host. This may go continually until you hit Control-C. Ping means a packet was sent from your machine via ICMP, and echoed at the IP level. ping tells you if the other Host is Up.
|
||||
|
||||
- telnet host <port> —- talk to “hosts” at the given port number. By default, the telnet port is port 23. Few other famous ports are:
|
||||
```
|
||||
7 – echo port,
|
||||
25 – SMTP, use to send mail
|
||||
79 – Finger, provides information on other users of the network
|
||||
```
|
||||
|
||||
Use control-] to get out of telnet.
|
||||
|
||||
#### Arp:
|
||||
|
||||
Arp is used to translate IP addresses into Ethernet addresses. Root can add and delete arp entries. Deleting them can be useful if an arp entry is malformed or just wrong. Arp entries explicitly added by root are permanent — they can also be by proxy. The arp table is stored in the kernel and manipulated dynamically. Arp entries are cached and will time out and are deleted normally in 20 minutes.
|
||||
|
||||
- arp –a : Prints the arp table
|
||||
- arp –s <ip_address> <mac_address> [pub] to add an entry in the table
|
||||
- arp –a –d to delete all the entries in the ARP table
|
||||
|
||||
#### Routing:
|
||||
|
||||
- netstat –r —- Print routing tables. The routing tables are stored in the kernel and used by ip to route packets to non-local networks.
|
||||
- route add —- The route command is used for setting a static (non-dynamic by hand route) route path in the route tables. All the traffic from this PC to that IP/SubNet will go through the given Gateway IP. It can also be used for setting a default route; i.e., send all packets to a particular gateway, by using 0.0.0.0 in the pace of IP/SubNet.
|
||||
- routed —– The BSD daemon that does dynamic routing. Started at boot. This runs the RIP routing protocol. ROOT ONLY. You won’t be able to run this without root access.
|
||||
- gated —– Gated is an alternative routing daemon to RIP. It uses the OSPF, EGP, and RIP protocols in one place. ROOT ONLY.
|
||||
- traceroute —- Useful for tracing the route of IP packets. The packet causes messages to be sent back from all gateways in between the source and destination by increasing the number of hopes by 1 each time.
|
||||
- netstat –rnf inet : it displays the routing tables of IPv4
|
||||
- sysctl net.inet.ip.forwarding=1 : to enable packets forwarding (to turn a host into a router)
|
||||
- route add|delete [-net|-host] <destination> <gateway> (ex. route add 192.168.20.0/24 192.168.30.4) to add a route
|
||||
- route flush : it removes all the routes
|
||||
- route add -net 0.0.0.0 192.168.10.2 : to add a default route
|
||||
- routed -Pripv2 –Pno_rdisc –d [-s|-q] to execute routed daemon with RIPv2 protocol, without ICMP auto-discovery, in foreground, in supply or in quiet mode
|
||||
- route add 224.0.0.0/4 127.0.0.1 : it defines the route used from RIPv2
|
||||
- rtquery –n : to query the RIP daemon on a specific host (manually update the routing table)
|
||||
|
||||
#### Others:
|
||||
|
||||
- nslookup —- Makes queries to the DNS server to translate IP to a name, or vice versa. eg. nslookup facebook.com will gives you the IP of facebook.com
|
||||
- ftp <host>water —– Transfer files to host. Often can use login=“anonymous” , p/w=“guest”
|
||||
- rlogin -l —– Logs into the host with a virtual terminal like telnet
|
||||
|
||||
#### Important Files:
|
||||
|
||||
```
|
||||
/etc/hosts —- names to ip addresses
|
||||
/etc/networks —- network names to ip addresses
|
||||
/etc/protocols —– protocol names to protocol numbers
|
||||
/etc/services —- tcp/udp service names to port numbers
|
||||
```
|
||||
|
||||
#### Tools and network performance analysis
|
||||
|
||||
- ifconfig <interface> <address> [up] : start the interface
|
||||
- ifconfig <interface> [down|delete] : stop the interface
|
||||
- ethereal & : it allows you open ethereal background not foreground
|
||||
- tcpdump –i -vvv : tool to capture and analyze packets
|
||||
- netstat –w [seconds] –I [interface] : display network settings and statistics
|
||||
- udpmt –p [port] –s [bytes] target_host : it creates UDP traffic
|
||||
- udptarget –p [port] : it’s able to receive UDP traffic
|
||||
- tcpmt –p [port] –s [bytes] target_host : it creates TCP traffic
|
||||
- tcptarget –p [port] it’s able to receive TCP traffic
|
||||
- ifconfig netmask [up] : it allows to subnet the sub-networks
|
||||
|
||||
|
||||
|
||||
#### Switching:
|
||||
|
||||
- ifconfig sl0 srcIP dstIP : configure a serial interface (do “slattach –l /dev/ttyd0” before, and “sysctl net.inet.ip.forwarding=1“ after)
|
||||
- telnet 192.168.0.254 : to access the switch from a host in its subnetwork
|
||||
- sh ru or show running-configuration : to see the current configurations
|
||||
- configure terminal : to enter in configuration mode
|
||||
- exit : in order to go to the lower configuration mode
|
||||
|
||||
#### VLAN:
|
||||
|
||||
- vlan n : it creates a VLAN with ID n
|
||||
- no vlan N : it deletes the VLAN with ID N
|
||||
- untagged Y : it adds the port Y to the VLAN N
|
||||
- ifconfig vlan0 create : it creates vlan0 interface
|
||||
- ifconfig vlan0 vlan ID vlandev em0 : it associates vlan0 interface on top of em0, and set the tags to ID
|
||||
- ifconfig vlan0 [up] : to turn on the virtual interface
|
||||
- tagged Y : it adds to the port Y the support of tagged frames for the current VLAN
|
||||
|
||||
#### UDP/TCP
|
||||
|
||||
- socklab udp – it executes socklab with udp protocol
|
||||
- sock – it creates a udp socket, it’s equivalent to type sock udp and bind
|
||||
- sendto <Socket ID> <hostname> <port #> – emission of data packets
|
||||
- recvfrom <Socket ID> <byte #> – it receives data from socket
|
||||
- socklab tcp – it executes socklab with tcp protocol
|
||||
- passive – it creates a socket in passive mode, it’s equivalent to socklab, sock tcp, bind, listen
|
||||
- accept – it accepts an incoming connection (it can be done before or after creating the incoming connection)
|
||||
- connect <hostname> <port #> – these two commands are equivalent to socklab, sock tcp, bind, connect
|
||||
- close – it closes the connection
|
||||
- read <byte #> – to read bytes on the socket
|
||||
- write (ex. write ciao, ex. write #10) to write “ciao” or to write 10 bytes on the socket
|
||||
|
||||
#### NAT/Firewall
|
||||
|
||||
- rm /etc/resolv.conf – it prevent address resolution and make sure your filtering and firewall rules works properly
|
||||
- ipnat –f file_name – it writes filtering rules into file_name
|
||||
- ipnat –l – it gives the list of active rules
|
||||
- ipnat –C –F – it re-initialize the rules table
|
||||
- map em0 192.168.1.0/24 -> 195.221.227.57/32 em0 : mapping IP addresses to the interface
|
||||
- map em0 192.168.1.0/24 -> 195.221.227.57/32 portmap tcp/udp 20000:50000 : mapping with port
|
||||
- ipf –f file_name : it writes filtering rules into file_name
|
||||
- ipf –F –a : it resets the rule table
|
||||
- ipfstat –I : it grants access to a few information on filtered packets, as well as active filtering rules
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://itsfoss.com/basic-linux-networking-commands/?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+ItsFoss+%28Its+FOSS%21+An+Open+Source+Blog%29
|
||||
|
||||
作者:[Abhishek Prakash][a]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://itsfoss.com/author/abhishek/
|
||||
[1]: https://drive.google.com/open?id=0By49_3Av9sT1cDdaZnh4cHB4aEk
|
@ -0,0 +1,140 @@
|
||||
你必须了解的 Linux 基础网络命令
|
||||
==================================================
|
||||
|
||||

|
||||
|
||||
摘要:有抱负的 Linux 系统管理员和 Linux 狂热者必须知道的最重要而且基础的 Linux 网络命令合集。
|
||||
|
||||
在 It’s FOSS 我们并非每天都谈论 Linux 的“命令行方面”。基本上,我更专注于 Linux 的桌面端。但你们读者中的一些人在内部调查(仅面向 It's FOSS newsletter 订阅者)中指出,你们也想学些命令行技巧。速查表也受大部分读者所喜欢和支持。
|
||||
|
||||
为此,我编辑了一个 Linux 中基础网络命令的列表。它并不是一个教你如何使用这些命令的教程,而是一个命令合集和他们的简短解释。所以,如果你已经使用过这些命令,你可以用它来快速记住命令。
|
||||
|
||||
你可以把这个网页添加为书签以便快速查阅,或下载这些命令的 PDF 版本以便离线使用。
|
||||
|
||||
当我还是通信系统工程专业的学生的时候我就有这个 Linux 网络命令的列表了。它帮助我在计算机网络课程获得了高分。希望它也能以同样的方式帮助你。
|
||||
|
||||
> 独家内容:[下载 Linux 网络命令速查表][1] 以便将来查阅。你可以打印或保存它以便离线查看。
|
||||
|
||||
### Linux 基础网络命令列表
|
||||
|
||||
我在计算机网络课程上使用 FreeBSD,不过这些 UNIX 命令应该也能在 Linux 上同样工作。
|
||||
|
||||
#### 连通性
|
||||
|
||||
- __ping <host\>__:发送 ICMP echo 消息(一个包)到主机。这可能会不停地发送直到你按下 Control-C。Ping 通意味着一个包从你的机器通过 ICMP 发送出去,并在 IP 层回显。Ping 告诉你另一个主机是否在运行。
|
||||
|
||||
- __telnet <host\> [port]__:与主机在指定的端口通信。默认的 telnet 端口是 23。其它一些常用的端口是:
|
||||
7 —— echo 端口
|
||||
25 —— SMTP,用于发送邮件
|
||||
79 —— Finger(译注:[维基百科 - Finger protocal](https://en.wikipedia.org/wiki/Finger_protocol)),提供该网络下其它用户的信息
|
||||
|
||||
按 Control-] 以退出 telnet。
|
||||
|
||||
#### ARP
|
||||
|
||||
ARP 用于将 IP 地址转换为以太网地址。Root 用户可以添加和删除 ARP 记录。当 ARP 记录被污染或者错误时,删除他们会有用。Root 显式添加的 ARP 记录是永久的 —— 代理设置的也是。ARP 表保存在内核中,动态地被操作。ARP 记录会被缓存,通常在 20 分钟后失效并被删除。
|
||||
|
||||
- __arp -a__:打印 ARP 表
|
||||
- __arp -s <ip_address\> <mac_address\> [pub]__:添加一条记录到表中
|
||||
- __arp -a -d__:删除 ARP 表中的所有记录
|
||||
|
||||
#### 路由
|
||||
|
||||
- __netstat -r__:打印路由表。路由表保存在内核中,用于 IP 层路由包到非本地网络。
|
||||
- __route add__:route 命令用于向路由表添加静态(手动输入而非动态)路由路径。所有从该 PC 到那个 IP/子网的流量都会经由指定的网关 IP。它也可以用来设置一个默认路由。例如,在 IP/子网处使用 0.0.0.0,就可以发送所有包到特定的网关。
|
||||
- __routed__:控制动态路由的 BSD 守护程序。开机时启动。它运行 RIP 路由协议。只有 root 用户可用。没有 root 权限你不能运行它。
|
||||
- __gated__:gated 是另一个使用 RIP 的路由守护进程。它同时支持 OSPF、EGP 和 RIP 协议。只有 root 用户可用。
|
||||
- __traceroute__:用于跟踪 IP 包的路由。它每次发送包时都把跳数加 1,从而使得从源地址到目的地之间的所有网关都会返回消息。
|
||||
- __netstat -rnf inet__:显示 IPv4 的路由表
|
||||
- __sysctl net.inet.ip.forwarding=1__:启用包转发(把主机变为路由器)
|
||||
- __route add|delete [-net|-host] <destination\> <gateway\>__:(如 `route add 192.168.20.0/24 192.168.30.4`)添加一条路由
|
||||
- __route flush__:删除所有路由
|
||||
- __route add -net 0.0.0.0 192.168.10.2__:添加一条默认路由
|
||||
- __routed -Pripv2 -Pno_rdisc -d [-s|-q]__:运行 routed 守护进程,使用 RIPv2 协议,不启用 ICMP 自动发现,在前台运行,供给模式或安静模式。
|
||||
- __route add 224.0.0.0/4 127.0.0.1__:定义 RIPv2 使用的路由(译注:翻译存疑)
|
||||
- __rtquery -n <host\>__(译注:增加了 host 参数):查询指定主机上的 RIP 守护进程(手动更新路由表)
|
||||
|
||||
#### 其它
|
||||
|
||||
- __nslookup__:向 DNS 服务器查询,将 IP 转为名称,或反之。例如,`nslookup facebook.com` 会给出 facebook.com 的 IP。
|
||||
- __ftp <host\> [port]__(译注:原文中 water 应是笔误):传输文件到指定主机。通常可以使用 login="anonymous" , p/w="guest" 登录。
|
||||
- __rlogin -l <host\>__(译注:添加了 host 参数):使用类似 telnet 的虚拟终端登录到主机
|
||||
|
||||
#### 重要文件
|
||||
|
||||
- __/etc/hosts__:域名到 IP 地址的映射
|
||||
- __/etc/networks__:网络名称到 IP 地址的映射
|
||||
- __/etc/protocols__:协议名称到协议编号的映射
|
||||
- __/etc/services__:TCP/UDP 服务名称到端口号的映射
|
||||
|
||||
#### 工具和网络性能分析
|
||||
|
||||
- __ifconfig <interface\> <address\> [up]__:启动接口
|
||||
- __ifconfig <interface\> [down|delete]__:停止接口
|
||||
- __ethereal &__:在后台打开 `ethereal` 而非前台
|
||||
- __tcpdump -i -vvv__:抓取和分析包的工具
|
||||
- __netstat -w [seconds] -I [interface]__:显示网络设置和统计信息
|
||||
- __udpmt -p [port] -s [bytes] target_host__:发送 UDP 流量
|
||||
- __udptarget -p [port]__:接收 UDP 流量
|
||||
- __tcpmt -p [port] -s [bytes] target_host__:发送 TCP 流量
|
||||
- __tcptarget -p [port]__:接收 TCP 流量
|
||||
|
||||
|
||||
#### 交换机
|
||||
|
||||
- __ifconfig sl0 srcIP dstIP__:配置一个序列接口(在此前先执行 `slattach -l /dev/ttyd0`,此后执行 `sysctl net.inet.ip.forwarding=1`)
|
||||
- __telnet 192.168.0.254__:从子网中的一台主机访问交换机
|
||||
- __sh ru__ 或 __show running-configuration__:查看当前配置
|
||||
- __configure terminal__:进入配置模式
|
||||
- __exit__:进入低级配置模式(译注:翻译存疑)
|
||||
|
||||
#### VLAN
|
||||
|
||||
- __vlan n__:创建一个 ID 为 n 的 VLAN
|
||||
- __no vlan N__:删除 ID 为 n 的 VLAN
|
||||
- __untagged Y__:添加端口 Y 到 VLAN n
|
||||
- __ifconfig vlan0 create__:创建 vlan0 接口
|
||||
- __ifconfig vlan0 vlan ID vlandev em0__:连接 vlan0 接口到 em0 之上(译注:翻译存疑),并设置标记为 ID
|
||||
- __ifconfig vlan0 [up]__:启用虚拟接口
|
||||
- __tagged Y__:为当前 VLAN 的端口 Y 添加标记帧支持
|
||||
|
||||
#### UDP/TCP
|
||||
|
||||
- __socklab udp__:使用 UDP 协议运行 `socklab`
|
||||
- __sock__:创建一个 UDP 套接字,等效于输入 `sock udp` 和 `bind`
|
||||
- __sendto <Socket ID\> <hostname\> <port #\>__:发送数据包
|
||||
- __recvfrom <Socket ID\> <byte #\>__:从套接字接收数据
|
||||
- __socklab tcp__:使用 TCP 协议运行 `socklab`
|
||||
- __passive__:创建一个被动模式的套接字,等效于 `socklab`,`sock tcp`,`bind`,`listen`
|
||||
- __accept__:接受进来的连接(可以在发起进来的连接之前或之后执行)
|
||||
- __connect <hostname\> <port #\>__:等效于 `socklab`,`sock tcp`,`bind`,`connect`
|
||||
- __close__:关闭连接
|
||||
- __read <byte #\>__:从套接字中读取 n 字节
|
||||
- __write__:(例如,`write ciao`、`write #10`)向套接字写入 "ciao" 或 10 个字节
|
||||
|
||||
#### NAT/防火墙
|
||||
|
||||
- __rm /etc/resolv.conf__:禁止地址解析,保证你的过滤和防火墙规则正确工作
|
||||
- __ipnat -f file_name__:将过滤规则写入文件
|
||||
- __ipnat -l__:显示活动的规则列表
|
||||
- __ipnat -C -F__:重新初始化规则表
|
||||
- __map em0 192.168.1.0/24 -> 195.221.227.57/32 em0__:将 IP 地址映射到接口
|
||||
- __map em0 192.168.1.0/24 -> 195.221.227.57/32 portmap tcp/udp 20000:50000__:带端口号的映射
|
||||
- __ipf -f file_name__:将过滤规则写入文件
|
||||
- __ipf -F -a__:重置规则表
|
||||
- __ipfstat -I__:在过滤的包上允许访问某些信息(译注:翻译存疑),也包括活动的过滤规则
|
||||
|
||||
希望这份基础的 Linux 网络命令合集对你有用。问题和建议总是受欢迎的。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://itsfoss.com/basic-linux-networking-commands
|
||||
|
||||
作者:[Abhishek Prakash][a]
|
||||
译者:[bianjp](https://github.com/bianjp)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://itsfoss.com/author/abhishek/
|
||||
[1]: https://drive.google.com/open?id=0By49_3Av9sT1cDdaZnh4cHB4aEk
|
@ -13,7 +13,21 @@ tar 命令语法如下:
|
||||
|
||||
下面列举 tar 命令中一些常用的选项:
|
||||
|
||||

|
||||
```
|
||||
--delete : 从归档文件 (而非磁带) 中删除
|
||||
-r, --append : 将文件追加到归档文件中
|
||||
-t, --list : 列出归档文件中包含的内容
|
||||
--test-label : 测试归档文件卷标并退出
|
||||
-u, --update : 将已更新的文件追加到归档文件中
|
||||
-x, --extract, --get : 释放归档文件中文件及目录
|
||||
-C, --directory-DIR : 执行归档动作前变更工作目录到 DIR
|
||||
-f, --file=ARCHIVE : 指定 (将要创建或已存在的) 归档文件名
|
||||
-j, --bip2 : 对归档文件使用 bzip2 压缩
|
||||
-J, --xz : 对归档文件使用 xz 压缩
|
||||
-p, --preserve-permissions : 保留原文件的访问权限
|
||||
-v, --verbose : 显示命令整个执行过程
|
||||
-z, gzip : 对归档文件使用 gzip 压缩
|
||||
```
|
||||
|
||||
注 : 在 tar 命令选项中的连接符 ( – ) 是可选的 (LCTT 译注:不用 - 也没事)。
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user