okx

Linux终端网络配置指南

时间:2023-06-23|浏览:163

这是一系列基础命令的集合,我会从使用角度介绍,看完这些以后你能够在Linux终端下完成大部分之前需要鼠标和键盘才能完成的操作。

今天是第五篇,介绍Linux下基础的网络操作命令。

网卡信息 ``` ubuntu@ubuntu-virtual-machine:~$ ifconfig ens33: flags=4163 mtu 1500 inet 192.168.115.138 netmask 255.255.255.0 broadcast 192.168.115.255 inet6 fe80::a1ed:ba47:821f:8b10 prefixlen 64 scopeid 0x20 ether 00:0c:29:51:ad:60 txqueuelen 1000 (Ethernet) RX packets 8665 bytes 12475254 (12.4 MB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 1103 bytes 98183 (98.1 KB) 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 1000 (Local Loopback) RX packets 188 bytes 16340 (16.3 KB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 188 bytes 16340 (16.3 KB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 ```

网络配置 主要列举几个我们在工作中可能会用到的操作: 关闭指定网卡 ``` #ifconfig eth0 down #关闭eth0 ```

开启指定网卡 ``` #ifconfig eth0 up #开启eth0 ```

修改指定网卡信息 ``` #ifconfig eth0 down #关闭网卡 #ifconfig eth0 hw ether 00:11:22:33:44:55 #修改eth0网卡MAC地址 #ifconfig eth0 up #启动网卡 ``` ``` #ifconfig eth0 192.168.3.178 #给eth0网卡配置IP地址 #ifconfig eth0 192.168.3.178 netmask 255.255.255.0 #给eth0网卡配置IP地址,并加上子掩码 #ifconfig eth0 192.168.3.178 netmask 255.255.255.0 broadcast 192.168.3.255 #给eth0网卡配置IP地址,加上子掩码,加上个广播地址 ```

启动/关闭ARP协议 如果对网络不熟悉可能不了解什么是ARP,但是这个协议在开发中是经常被用到的,可以先了解一下。 ``` #ifconfig eth0 arp #开启eth0网卡ARP #ifconfig eth0 -arp #关闭eth0网卡ARP ```

设置MTU MTU是包或帧的最大长度,一般单位是字节。如果MTU过大,在碰到路由器时会被拒绝转发,因为它不能处理过大的包。如果太小,因为协议一定要在包(或帧)上加上包头,那实际传送的数据量就会过小,这样也划不来。大部分操作系统会提供给用户一个默认值,该值一般对用户来说是比较合适的。 ``` #ifconfig eth0 mtu 1500 #设置MTU1500字节 ```

ping命令 ping命令一般用来测试网络连通状态,但是一定要注意,并不是说没有ping通就表示网络不通,因为网络可以配置ping的功能,但是大多数情况下都有这个服务。

使用非常简单,ping命令紧接着一个IP或者域名地址,需要手动输入CTRL+C结束。 ``` ubuntu@ubuntu-virtual-machine:~$ ping 192.168.3.178 PING 192.168.3.178 (192.168.3.178) 56(84) bytes of data. 64 bytes from 192.168.3.178: icmp_seq=1 ttl=128 time=4.90 ms 64 bytes from 192.168.3.178: icmp_seq=2 ttl=128 time=5.08 ms 64 bytes from 192.168.3.178: icmp_seq=3 ttl=128 time=5.26 ms ^C --- 192.168.3.178 ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2002ms rtt min/avg/max/mdev = 4.904/5.081/5.260/0.145 ms

ubuntu@ubuntu-virtual-machine:~$ ping www.baidu.com PING www.a.shifen.com (14.215.177.39) 56(84) bytes of data. 64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=1 ttl=128 time=34.2 ms 64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=2 ttl=128 time=33.5 ms 64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=3 ttl=128 time=33.8 ms 64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=4 ttl=128 time=36.1 ms ^C --- www.a.shifen.com ping statistics --- 4 packets transmitted, 4 received, 0% packet loss, time 3007ms rtt min/avg/max/mdev = 33.524/34.393/36.068/0.992 ms ```

介绍几个常用的参数: -c 指定ping的包数。 ``` ubuntu@ubuntu-virtual-machine:~$ ping -c 5 www.baidu.com PING www.a.shifen.com (14.215.177.39) 56(84) bytes of data. 64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=1 ttl=128 time=34.8 ms 64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=2 ttl=128 time=35.4 ms 64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=3 ttl=128 time=36.8 ms 64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=4 ttl=128

热点:nft终端 矿机配置 比特币指南 nft指南 币圈指南

欧易

欧易(OKX)

用戶喜愛的交易所

币安

币安(Binance)

已有账号登陆后会弹出下载

« 上一条| 下一条 »
区块链交流群
数藏交流群

合作伙伴

非小号交易所排名-专业的交易行情资讯门户网站,提供区块链比特币行情查询、比特币价格、比特币钱包、比特币智能合约、比特币量化交易策略分析,狗狗币以太坊以太币玩客币雷达币波场环保币柚子币莱特币瑞波币公信宝等虚拟加密电子数字货币价格查询汇率换算,币看比特儿火币网币安网欧易虎符抹茶XMEX合约交易所APP,比特币挖矿金色财经巴比特范非小号资讯平台。
非小号行情 yonghaoka.cn 飞鸟用好卡 ©2020-2024版权所有 桂ICP备18005582号-1