Linux 网络net-tools工具箱

虽说net-tools工具箱要被iproute2取代,但是连net-tools工具都不会,也说不过去吧。

net-tools工具箱包括arp, hostname, ifconfig, netstat, rarp, route, plipconfig, slattach, mii-tool and iptunnel and ipmaddr等命令。

一、ifconfig

1. ifconfig:查看已启用的网卡信息

2. ifconfig -a:查看所有网卡信息(包括未激活的),这个a表示all:display all interfaces which are currently available, even if down。

3. ifconfig eth0:查看单个网卡信息(后面表示单个网口名都用eth0表示)

4. ifconfig eth0 up/down:激活/关闭某个端口

5. ifconfig eth0 192.168.1.2/24 ifconfig eth0 192.168.1.2 255.255.255.0 :设置网卡IP地址

6. ifconfig eth0 hw ether 00:11:22:33:44:55:设置网卡MAC地址

7. ifconfig eth0 0:删除网卡IP地址

8. ifconfig -s:short,显示网卡简短的信息

Linux 网络net-tools工具箱

Linux 网络net-tools工具箱

Linux 网络net-tools工具箱

二、arp

https://linux.die.net/man/8/arp

https://www.cnblogs.com/wj78080458/p/10358033.html

-n:以数字方式显示,不进行端口,名称等解析

-a:显示所有条目

-a ipaddr:查看指定ip地址的arp表项

-i:指定设备,查看某个设备的arp缓存

-s:添加arp缓存项目

-d:删除arp缓存条目

-i:指定设备,查看某个设备的arp缓存

Linux 网络net-tools工具箱

-a ipaddr:查看指定ip地址的arp表项

Linux 网络net-tools工具箱

-s:添加arp缓存项目

Linux 网络net-tools工具箱

-d:删除arp缓存条目

这个C标志的感觉删不掉呀,这个CM的可用删除。

Linux 网络net-tools工具箱

CM:表示arp表项是静态的,C:表示arp表项是动态的。

添加arp表项的时候,可用加上temp,表示表项是动态的,如下:

https://blog.csdn.net/surfer1212/article/details/1357342

Linux 网络net-tools工具箱

三、route

https://linux.die.net/man/8/route

https://www.cnblogs.com/machangwei-8/p/10352872.html

https://www.cnblogs.com/baiduboy/p/7278715.html

https://blog.csdn.net/u011857683/article/details/83795435

看看route命令的man手册语法:

SYNOPSIS
route [-CFvnNee] [-A family |-4|-6]
route  [-v]  [-A  family |-4|-6] add [-net|-host] target [netmask Nm] [gw Gw] [metric N] [mss M] [window W] [irtt I] [reject] [mod]
              [dyn] [reinstate] [[dev] If]
route  [-v] [-A family |-4|-6] del [-net|-host] target [gw Gw] [netmask Nm] [metric M] [[dev] If]
route  [-V] [--version] [-h] [--help]

参数说明:

-n:不进行名称解析

add:添加一条新路由。

del:删除一条路由。

-net:目标地址是一个网络。

-host:目标地址是一个主机。

netmask:当添加一个网络路由时,需要使用网络掩码。

gw:路由数据包通过网关。注意,你指定的网关必须能够达到。

metric:设置路由跳数。

Linux 网络net-tools工具箱

U (route is up),路由是开启的
H (target is a host),表示到主机的路由
G (use gateway),表示默认路由
R (reinstate route for dynamic routing)
D (dynamically installed by daemon or redirect)
M (modified from routing daemon or redirect)
A (installed by addrconf)
C (cache entry)
! (reject route) ,拒绝路由

Metric

目标的距离,通用用跳数计算,内核中没有使用,可能守护进程有用到这个。

The 'distance' to the target (usually counted in hops). It is not used by recent kernels, but may be needed by routing daemons.

Ref

这条路由的引用计数,在内核中没有使用

Number of references to this route. (Not used in the Linux kernel.)

1.添加和删除路由:

route {add | del } [-net|-host] [网域或主机] netmask [mask] [gw|dev]
 
 
增加 (add) 与删除 (del) 路由的相关参数:
(a) -net :表示后面接的路由为一个网域。
(b) -host :表示后面接的为连接到单部主机的路由。
(c) netmask :与网域有关,可以设定 netmask 决定网域的大小。
(d) gw :gateway 的简写,后续接的是 IP 的数值,与 dev 不同。
(e) dev :如果只是要指定由那一块网路卡连线出去,则使用这个设定,后面接 eth0 等。
Linux 网络net-tools工具箱

Linux 网络net-tools工具箱

2.指定地址不可达

设置到指定网络为不可达,避免在连接到这个网络的地址时程序过长时间的等待,直接就知道该网络不可达。
 
route {add | del } -net {NETWORK-ADDRESS} netmask {NETMASK} reject
 
(a) NETWORK-ADDRESS:用于指定网络地址。
(b) NETMASK:用于指定子网掩码。
 
 
例1:route add -net 10.0.0.0 netmask 255.0.0.0 reject
例2:route del -net 10.0.0.0 netmask 255.0.0.0 reject
Linux 网络net-tools工具箱

Linux 网络net-tools工具箱

Linux 网络net-tools工具箱

网络   Linux   net
发表评论
留言与评论(共有 0 条评论) “”
   
验证码:

相关文章

推荐文章