Linux常用网络指令

本文详细介绍了一系列网络参数设置命令,如ifconfig、ifup、route等,以及网络调试与观察命令,如ping、traceroute等。此外还介绍了远程连接命令如telnet、ftp等的使用方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

网络参数设定命令:

1.ifconfig                                         #启动修改网络接口的相关参数

[root@linux ~]# ifconfig {interface} {up|down}        #与启动接口

[root@linux ~]# ifconfig interface {options}          #修改接口

options

updown     #启动关闭网络接口

mtu          # MTU

netmask      #定子      

broadcast    #定广播地址

[root@linux ~]# ifconfig eth0 192.168.100.100 netmask 255.255.255.128 mtu 8000

#注意:重新启动网络后,所做配置失效,仍然以 /etc/sysconfig/network-scripts/ifcfg-ethx

#配置文件配置网络参数

 

2.ifup, ifdown           #直接以/etc/sysconfig/network-scripts/ifcfg-ethx 启动网络

[root@linux ~]# ifup / ifdown   {interface}

#注意:ifconfig 设定过的接口,无法直接用ifdown关闭,因为ifdown需要核对配置文件,所以必须再用#ifconfig才能关闭接口

 

3.route                  #查询定路由表

[root@linux ~]# route [-nee]

[root@linux ~]# route add [-net|-host] [段或主机] netmask [mask] [gw|dev]

[root@linux ~]# route del [-net|-host] [段或主机] netmask [mask] [gw|dev] 

-n         # IP port number 取代通讯协议或主机名

-ee        #详细信息

-net       #表示后面接的路由个网

-host      #表示后面接的是接到一主机的路由

Netmask    # netmask 段的大小

Gw         #gateway 简写,接 IP 地址, dev 不同

Dev        #指定由某块网机出去,接 eth0

[root@linux ~]# route -n   #查询结示的序就是默的路由

Flags 

o  U route is up                                             #路由以启动

o  H target is a host                                        #是主机

o  G use gateway                                             #使用外部主机传递数据包

o  R reinstate route for dynamic routing                     #使用动态路由,恢路由信息的标记

o  D dynamically installed by daemon or redirect             #为动态路由

o  M modified from routing daemon or redirect                #路由被修改

o  ! reject route                                            #不接受此路由

 

[root@linux ~]# route del -net 169.254.0.0 netmask 255.255.0.0 dev eth0

[root@linux ~]# route add -net 192.168.100.0 netmask 255.255.255.0 dev eth0

[root@linux ~]# route add default gw 192.168.10.30           #路由

 

4.ip                                                         #可以直接修改上面提到的功能

[root@linux ~]# ip [option] [] [指令]

option

-s                                                    #统计数(statistics),例如接受封包

                        #针对哪种网络参数进行操作 括:

   Link              #于装置 (device) 的相关设定,包括 MTU, MAC 地址等

   addr/address      #外的 IP 协议,多IP实现

   Route             #路由有的相关设

  

1) ip link

[root@linux ~]# ip [-s] link show [device]                   #看装置相信息

[root@linux ~]# ip link set [device] [与参数]

Show                                                         #设备的相信息

Set                                                          #

与参数

up|down                                                      #启动关闭接口

address                                                      #更改 MAC

Name                                                         #更改设备

Mtu                                                          #MTU

[root@linux ~]# ip link show                                 #示所有接口信息

[root@linux ~]# ip -s link show eth0

[root@linux ~]# ip link set eth0 up/down                     #启动关闭接口

[root@linux ~]# ip link set eth0 mtu 1000                    #MTU 位是bytes

[root@linux ~]# ip link set eth0 name vbird                  #定接口名,需关闭此接口

[root@linux ~]# ip link set eth0 address aa:aa:aa:aa:aa:aa   #MAC

 

2)  ip address

[root@linux ~]# ip address show [device]                     #IP参数

[root@linux ~]# ip address [add|del] [IP参数] [dev 装置名] [关参数]

Show                                                         #示接口IP信息

add|del                                                      #行相关参数的增加或除,主要有:

IP 参数   段的定,例如 192.168.100.100/24

Dev      :所要定的接口,例如 eth0, eth1

关参数:主要有:

Broadcast            定广播地址,如果 + 表示『动计算』

Labe                 : 装置的名,例如 eth0:0

Scope                : 接口的范,通常是:

global :允许来自所有源的机,是默认值

site   支持 IPv6 本主机的

link   设备自我

host   本主机部的

[root@linux ~]# ip address show                             #示所有接口IP参数

[root@linux ~]# ip address add 192.168.50.50/24 broadcast + dev eth0 label eth0:vbird

#新增一特殊接口

[root@linux ~]# ip address del 192.168.50.50/24 dev eth0    #才新增的接口

 

3)  ip route

[root@linux ~]# ip route show [device]                      #示路由

[root@linux ~]# ip route [add|del] [IP] [via gateway] [dev 设备]

参数

Show                                                        #示路由表,也可以使用 list

add|del                                                     #增加或除路由

IP                                                    #192.168.50.0/24段或IP

Via                                                         #从哪个gateway出去,不一定需要 

Dev                                                         #由那装置出去,必选项 

Mtu                                                         #可以 MTU 数值

[root@linux ~]# ip route show                               #显示路由信息

Proto                                   #路由的路由协议,主要redirect, kernel, boot, static, #ra等,其中 kernel 指的是直接由核心判动设 

Scope                                   #路由的范,主要是 link ,即设备的直接

[root@linux ~]# ip route add 192.168.5.0/24 dev eth0                #增加路由

[root@linux ~]# ip route add 192.168.10.0/24 via 192.168.5.100 dev eth0

[root@linux ~]# ip route add default via 192.168.1.2 dev eth0   #设定默认路由

[root@linux ~]# ip route del 192.168.10.0/24                           #删除路由

 

iwlist                                                          #侦测线 AP 的相关参数

iwconfig                                                        #定无线网卡的相关参数

[root@linux ~]# dhclient eth0                                   #DHCP

网络侦错与观察指令

[root@linux ~]# ping [-bcstnM] IP

-b    #broadcast IP针对个网段的主机PING

-c    # ping 的次,例如 -c 5

-n    # IP 主机名的反,直接使用 IP

-s    #送出去的 ICMP 封包大小,默认为 56bytes,再加 8 bytes ICMP

-t    #TTL,默255,每经过个节递减1

-M [do|dont]   #侦测网络 MTU 数值两个目:

   Do    #代表送一 DF (Don't Fragment)志,使封包不能重新拆包打包

   Don   #代表不 DF ,表示封包可以在其主机上拆包打包

[root@linux ~]# ping -c 3 192.168.1.1

[root@linux ~]# ping -c 3 -b 192.168.10.255                       #PING个网

[root@linux ~]# ping -c 2 -s 1000 -M do 192.168.10.10             #找出最大的 MTU 数值

[root@linux ~]# ping -c 2 -s 8000 -M do 192.168.10.10

[root@linux ~]# traceroute [-nwig] IP

-n     #不解析主机名,只用 IP ,速度

-w     #方主机在几秒钟内没有回就宣告失预设 5

-i     #用在复杂环境,如果网络接口,例如有两条 ADSL 接到外部,主机两个 ppp

       #可以使用 -i 来选择 ppp0 ppp1

-g     #与参数 -i 似,但是 -g 后面接 gateway IP

[root@linux ~]# traceroute -n www.yahoo.com.cn

[root@linux ~]# netstat -[rn]                                     #路由有参数

[root@linux ~]# netstat -[antulpc]                                 #与网络接口有参数

-r     #列出路由表,同 route

-n     #不使用主机名称与,使 IP port number ,同 route -n

-a     #列出所有的状态,包括 tcp/udp/unix socket

-t     #列出 TCP 封包的

-u     #列出 UDP 封包的

-l     #列出 Listen () 网络状态的服

-p     #列出 PID Program 的文件名

-c     #定几秒更新一次,例如 -c 5 每五秒更新一次网络状态

[root@linux ~]# netstat –rn                                        #列出路由表

[root@linux ~]# netstat –an                                        #列出所有状态

[root@linux ~]# netstat –tulnp                                     #列出已经启动网络

[root@linux ~]# netstat –atunp                                     #看主机所有网络联状态

[root@linux ~]# host [-a] hostname [server]                         #IP

[root@linux ~]# host www.yahoo.com.cn

[root@linux ~]# host www.yahoo.com.cn 168.95.1.1                    #指定DNS主机反IP

[root@linux ~]# nslookup www.yahoo.com.cn                           #IP

[root@linux ~]# nslookup 168.95.1.1                                 #主机名

机指令

[root@linux ~]# telnet [host|IP] [port]

[root@linux ~]# telnet bbs.dorm.ncku.edu.tw

root@linux ~]# telnet localhost 110                                 #侦测端口是否启动

[root@linux ~]# ftp [-p] [host|IP] [port]

-p     #启动被动式模式 (passive, PASV)

[root@linux ~]# ftp ftp.isu.edu.tw

ftp> help                                                           #提供

ftp> cd /pub                                                        #变换

ftp> dir                                                            #程主机的目录内

ftp> get file                                                       # file 这个文件

ftp> mget file                                                      # file 这个文件

ftp> put file                                                       # file 这个文件到服

ftp> delete file                                                    #除主机上的 file 这个文件

ftp> mkdir dir                                                      #建立 dir 这个

ftp> lcd /home                                                      #『本地端主机』的工作目

ftp> passive                                                        #启动关闭 passive 模式

ftp> binary                                                         #传输模式 binary 格式

[root@linux ~]# lftp [-p port] [-u user[,pass]] [host|IP]

-p     #后面接 FTP 主机提供的 port

-u     #后面接账号与

[root@linux ~]# lftp ftp.isu.edu.tw

[root@linux ~]#gaim                                                   #X下的MSN

文字接口网页浏览:

[root@linux ~]# lynx [options] [website]

options      #常用参数,使用 man lynx 看,常有:

     -anonymous                                                        #使用匿名登入

     -assume_charset=big5                                              #定默认语

[root@linux ~]#LANG=en_US                                              #系,否无法正常示中文

[root@linux ~]#lynx http://www.kernel.org

[root@linux ~]# vi /etc/lynx.cfg                                       #永久更改

[root@linux ~]# wget [option] []

--http-user=usrname

--http-password=password

--quiet     # wget 候的

[root@linux ~]# wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.17.tar.gz

[root@linux ~]# vi /etc/wgetrc                                         #定代理服

[root@linux ~]# tcpdump [-nn] [-i ] [-w ] [-c ] [-Ae] [-qX] [-r ] [想要取的]

-nn     #直接以 IP port number

-i      #接要『听』的网络接口

-w      #保存取的容到文件

-c      #听的封包取的次

-A      #封包的容以 ASCII 示,通常用捉取 WWW 网页封包

-e      #使用数据链路层 MAC 封包

-q      #出简短的封包信息

-X      #列出十六 (hex) 以及 ASCII 的封包容,可用听封包

-r      #后面接的文件将封包。『文件』是已存在的文件

 #这个文件』是由 -w 生成的

想要取的     #可以专门针对某些通讯协议或者是 IP 行封包取,这样就可以出,只取有用信息。常的表示方法有:

'host foo', 'host 127.0.0.1'                #对单一主机行封包

'net 192.168'                               #个网行封包

'src host 127.0.0.1' 'dst net 192.168'      #加上(src)或目(dst)限制

'tcp port 21'                               #讯协议侦测,如tcp, udp, arp, ether

    #可以利用 and or 行封包据的整合

[root@linux ~]# tcpdump -i eth0 –nn               #eth0

[root@linux ~]# tcpdump -i eth0 -nn port 21        #取端口21的封包

[root@linux ~]# tcpdump -i eth0 -nn 'port 22 and src host 192.168.1.100'

[root@linux ~]# tcpdump -i lo -nn -X 'port 21'

[root@linux ~]# tethereal                                #功能tcpdump                                                   #也可在Xethereal形界面

[root@linux ~]# nc [IP|host] [port]

[root@linux ~]# nc -l -p [port]

-l     #为监听用,即开启 port 来监听用

-p     #开启这个 port number

[root@linux ~]# nc localhost 25                                               #接本地 port 25

[root@linux ~]# nc -l -p 20000                                                #激活一 port

[root@linux ~]# nc localhost 20000                                            #机到客

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值