Linux网络配置

本文围绕Linux系统的网络配置与测试展开。详细介绍了查看网络接口、ARP缓存表、路由表等操作的命令,还说明了开启rsync服务及查看端口监听情况的方法。同时,阐述了网络连通性测试、激活网卡、添加IP地址、设置静态路由和默认网关等网络测试与配置的步骤。

1.查看网络配置
问题
1)根据以下要求查看接口信息
2)分别查看物理网卡、lo回环接口的信息
3)列出所有的网络接口
4)ping一下网关地址,然后查看ARP缓存表
5)查看本机的路由表
6)开启临时服务rsync
7)查询rsync服务的端口号(/etc/services)
8)利用netstat命令查看系统是否在监听此端口
方案
查看网络接口的命令为ifconfig,常用的选项为“-a”,可以列出所有网络接口的信息。
利用arp -an命令可以查看本机的ARP缓存表,需注意的是ARP缓存表是临时生成的,在查看前需要ping一下其它主机,生成一条ARP缓存记录。
查看路由表命令为route –n。其中有标记“U”为直连路由,“UG”为静态路由。
可以利用netstat –anptu命令,查看本机当前监听的都有哪些端口。可以利用“|”交由grep命令进行筛选。
步骤
实现此案例需要按照如下步骤进行。
步骤一:根据以下要求查看接口信息
分别查看物理网卡、lo回环接口的信息。
命令操作如下所示:
[root@localhost 桌面]# ifconfig eth0 //查看eth0网卡信息
eth0 Link encap:Ethernet HWaddr 00:0C:29:0D:06:9A
inet addr:192.168.1.1 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe0d:69a/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:10596 errors:0 dropped:0 overruns:0 frame:0
TX packets:74 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:757148 (739.4 KiB) TX bytes:10154 (9.9 KiB)

[root@localhost 桌面]# ifconfig lo //查看lo回环接口信息
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:80 errors:0 dropped:0 overruns:0 frame:0
TX packets:80 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:6328 (6.1 KiB) TX bytes:6328 (6.1 KiB)
[root@localhost 桌面]#
列出所有的网络接口,命令操作如下所示:
[root@localhost 桌面]# ifconfig -a
eth0 Link encap:Ethernet HWaddr 00:0C:29:0D:06:9A
inet addr:192.168.1.1 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe0d:69a/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:16800 errors:0 dropped:0 overruns:0 frame:0
TX packets:74 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:1201546 (1.1 MiB) TX bytes:10154 (9.9 KiB)

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:80 errors:0 dropped:0 overruns:0 frame:0
TX packets:80 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:6328 (6.1 KiB) TX bytes:6328 (6.1 KiB)

[root@localhost 桌面]#
步骤二:ping一下网关地址,然后查看ARP缓存表
分析: 利用dhclient命令来获取网关与IP地址。
命令操作如下所示:
[root@localhost 桌面]# dhclient –r //释放现有IP地址
[root@localhost 桌面]# dhclient //从新获取
[root@localhost 桌面]# ifconfig eth0
eth0 Link encap:Ethernet HWaddr 00:0C:29:0D:06:9A
inet addr:192.168.30.124 Bcast:192.168.30.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe0d:69a/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:25598 errors:0 dropped:0 overruns:0 frame:0
TX packets:98 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:1811539 (1.7 MiB) TX bytes:13766 (13.4 KiB)

[root@localhost 桌面]# route –n //查看路由表
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.30.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
0.0.0.0 192.168.30.2 0.0.0.0 UG 0 0 0 eth0
[root@localhost 桌面]# ping 192.168.30.2 //与网关通信
PING 192.168.30.2 (192.168.30.2) 56(84) bytes of data.
64 bytes from 192.168.30.2: icmp_seq=1 ttl=64 time=50.4 ms
64 bytes from 192.168.30.2: icmp_seq=2 ttl=64 time=83.3 ms
64 bytes from 192.168.30.2: icmp_seq=3 ttl=64 time=5.55 ms
^C //按ctrl+c结束
— 192.168.30.2 ping statistics —
3 packets transmitted, 3 received, 0% packet loss, time 2374ms
rtt min/avg/max/mdev = 5.557/46.480/83.388/31.900 ms
[root@localhost 桌面]# arp –an //查看ARP缓存表
? (192.168.30.2) at 50:bd:5f:35:f7:b2 [ether] on eth0
[root@localhost 桌面]#
步骤三:查看本机的路由表
命令操作如下所示:
[root@localhost 桌面]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.30.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
0.0.0.0 192.168.30.2 0.0.0.0 UG 0 0 0 eth0
[root@localhost 桌面]#
步骤四:开启临时服务rsync
查询rsync服务的端口号(/etc/services )。
命令操作如下所示:
[root@localhost 桌面]# rpm -q rsync //查询本机是否安装rsync
rsync-3.0.6-9.el6_4.1.x86_64
[root@localhost 桌面]# rpm -q xinetd //查询本机是否安装xinetd
xinetd-2.3.14-39.el6_4.x86_64
[root@localhost 桌面]# ls /etc/xinetd.d/rsync
/etc/xinetd.d/rsync
[root@localhost 桌面]#
[root@localhost 桌面]# grep disable /etc/xinetd.d/rsync
disable = yes
[root@localhost 桌面]# chkconfig rsync on //将yes改成no
[root@localhost 桌面]# grep disable /etc/xinetd.d/rsync
disable = no
[root@localhost 桌面]# /etc/init.d/xinetd restart
停止 xinetd: [失败]
正在启动 xinetd: [确定]
[root@localhost 桌面]# grep rsync /etc/services
rsync 873/tcp # rsync
rsync 873/udp # rsync
… …
利用netstat命令查看系统是否在监听此端口。
命令操作如下所示:
[root@localhost 桌面]# netstat -anptu | grep 873
tcp 0 0 :::873 ::? LISTEN 3186/xinetd
[root@localhost 桌面]#
2.测试网络
问题
1)网络连通性测试
2)ping本网段另一台主机的IP地址,观察结果
3)ping一个不存在的主机地址,观察结果
4)查询站点www.baidu.com的IP地址是多少
5)使用host命令进行解析,观察执行结果
6)使用nslookup命令进行解析,观察执行结果
方案
ping命令在Linux中,默认情况下会一直与目的端发送ping包。要想结束可以按快捷键Ctrl+c结束。
ping命令常用的选项:-c 包个数、-s 包大小。
步骤
实现此案例需要按照如下步骤进行。
步骤一:网络连通性测试
ping本网段另一台主机的IP地址,观察结果。
命令操作如下所示:
[root@localhost 桌面]# ifconfig eth0
eth0 Link encap:Ethernet HWaddr 00:0C:29:0D:06:9A
inet addr:192.168.30.124 Bcast:192.168.30.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe0d:69a/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:102867 errors:0 dropped:0 overruns:0 frame:0
TX packets:180 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:7237411 (6.9 MiB) TX bytes:21320 (20.8 KiB)

[root@localhost 桌面]# ping -c 3 192.168.30.2 //-c可以控制ping包个数
PING 192.168.30.2 (192.168.30.2) 56(84) bytes of data.
64 bytes from 192.168.30.2: icmp_seq=1 ttl=64 time=405 ms
64 bytes from 192.168.30.2: icmp_seq=2 ttl=64 time=91.8 ms
64 bytes from 192.168.30.2: icmp_seq=3 ttl=64 time=17.8 ms

— 192.168.30.2 ping statistics —
3 packets transmitted, 3 received, 0% packet loss, time 2036ms
rtt min/avg/max/mdev = 17.833/171.779/405.622/168.093 ms
[root@localhost 桌面]#
ping一个不存在的主机地址,观察结果,命令操作如下所示:
[root@localhost 桌面]# ping 1.1.1.1
connect: 网络不可达
[root@localhost 桌面]#
步骤二:查询站点www.baidu.com的IP地址是多少
使用host命令进行解析,观察执行结果,命令操作如下所示:
[root@localhost ~]# host www.baidu.com
www.baidu.com is an alias for www.a.shifen.com.
www.a.shifen.com has address 119.75.217.109
www.a.shifen.com has address 119.75.218.70
[root@localhost ~]#
使用nslookup命令进行解析,观察执行结果,命令操作如下所示:
[root@localhost ~]# nslookup www.baidu.com
Server: 192.168.30.1
Address: 192.168.30.1#53 //DNS服务器地址

Non-authoritative answer:
www.baidu.com canonical name = www.a.shifen.com.
Name: www.a.shifen.com
Address: 119.75.217.109
Name: www.a.shifen.com
Address: 119.75.218.70

[root@localhost ~]#
3.临时配置
问题
1)网络接口控制
2)查看网卡eth0的配置信息、禁用网卡eth0
3)列出所有网络接口,确认启用状态
4)激活网卡eth0,将地址设置为 192.168.4.5/24
5)为网卡eth0添加一个IP地址 192.168.8.5/24
6)为本机设置静态路由记录
7)访问网段200.0.0.0/24可经192.168.8.100抵达
8)默认网关的IP地址为 192.168.8.254
方案
临时配置:简单快速,可直接更改运行中的地址参数,适合在调试网络的过程中使用;系统重启以后,所做的修改将会失效。
配置静态路由时,下一跳地址一定要是本网段地址。目标地址要写网段ID,必须写上子网掩码。配置网关地址时,网关地址必须为本网段地址。
步骤
实现此案例需要按照如下步骤进行。
步骤一:网络接口控制
查看网卡eth0的配置信息、禁用网卡eth0,命令操作如下所示:
root@localhost 桌面]# ifconfig eth0
eth0 Link encap:Ethernet HWaddr 00:0C:29:0D:06:9A
inet addr:192.168.30.124 Bcast:192.168.30.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe0d:69a/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:174884 errors:0 dropped:0 overruns:0 frame:0
TX packets:920 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:12269223 (11.7 MiB) TX bytes:91973 (89.8 KiB)

[root@localhost 桌面]# ifconfig eth0 down
[root@localhost 桌面]# ifconfig
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:105 errors:0 dropped:0 overruns:0 frame:0
TX packets:105 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:8792 (8.5 KiB) TX bytes:8792 (8.5 KiB)
列出所有网络接口,确认启用状态,命令操作如下所示:
[root@localhost 桌面]# ifconfig -a
eth0 Link encap:Ethernet HWaddr 00:0C:29:0D:06:9A
inet addr:192.168.30.124 Bcast:192.168.30.255 Mask:255.255.255.0
BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:175179 errors:0 dropped:0 overruns:0 frame:0
TX packets:920 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:12289943 (11.7 MiB) TX bytes:91973 (89.8 KiB)

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:105 errors:0 dropped:0 overruns:0 frame:0
TX packets:105 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:8792 (8.5 KiB) TX bytes:8792 (8.5 KiB)

[root@localhost 桌面]#
激活网卡eth0,将地址设置为192.168.4.5/24,命令操作如下所示:
[root@localhost 桌面]# ifconfig
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:105 errors:0 dropped:0 overruns:0 frame:0
TX packets:105 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:8792 (8.5 KiB) TX bytes:8792 (8.5 KiB)

[root@localhost 桌面]# ifconfig eth0 up
[root@localhost 桌面]# ifconfig
eth0 Link encap:Ethernet HWaddr 00:0C:29:0D:06:9A
inet addr:192.168.30.124 Bcast:192.168.30.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe0d:69a/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:175553 errors:0 dropped:0 overruns:0 frame:0
TX packets:927 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:12315815 (11.7 MiB) TX bytes:92551 (90.3 KiB)

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:105 errors:0 dropped:0 overruns:0 frame:0
TX packets:105 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:8792 (8.5 KiB) TX bytes:8792 (8.5 KiB)

[root@localhost 桌面]# ifconfig eth0 192.168.4.5/24
[root@localhost 桌面]# ifconfig
eth0 Link encap:Ethernet HWaddr 00:0C:29:0D:06:9A
inet addr:192.168.4.5 Bcast:192.168.4.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe0d:69a/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:177266 errors:0 dropped:0 overruns:0 frame:0
TX packets:927 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:12438744 (11.8 MiB) TX bytes:92551 (90.3 KiB)

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:105 errors:0 dropped:0 overruns:0 frame:0
TX packets:105 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:8792 (8.5 KiB) TX bytes:8792 (8.5 KiB)

[root@localhost 桌面]#
步骤二:为网卡eth0添加一个IP地址 192.168.8.5/24
命令操作如下所示:
[root@localhost 桌面]# ifconfig eth0 192.168.8.5/24
[root@localhost 桌面]# ifconfig eth0
eth0 Link encap:Ethernet HWaddr 00:0C:29:0D:06:9A
inet addr:192.168.8.5 Bcast:192.168.8.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe0d:69a/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:182405 errors:0 dropped:0 overruns:0 frame:0
TX packets:927 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:12804365 (12.2 MiB) TX bytes:92551 (90.3 KiB)

[root@localhost 桌面]#
步骤三:为本机设置静态路由记录
访问网段200.0.0.0/24可经192.168.8.100抵达。
添加一条静态路由route add -net 200.0.0.0/24 gw 192.168.8.100 ,相关说明如下所示:
route add:添加一条路由条目;
-net:目标网络ID和子网掩码;
gw:下一跳地址。
命令操作及输出结果如下所示:
[root@localhost 桌面]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.8.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
[root@localhost 桌面]# route add -net 200.0.0.0/24 gw 192.168.8.100
[root@localhost 桌面]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
200.0.0.0 192.168.8.100 255.255.255.0 UG 0 0 0 eth0
192.168.8.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
默认网关的IP地址为 192.168.8.254。
分析:为PC机配置网关,而对PC机而言数据只要是跨网通信都必须交给网关处理,这很像路由中的默认路由的概念。所以在Linux中为PC机配置网关,其实就是配置一条默认路由。
命令操作如下所示:
[root@localhost 桌面]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
200.0.0.0 192.168.8.100 255.255.255.0 UG 0 0 0 eth0
192.168.8.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
[root@localhost 桌面]# route add default gw 192.168.8.254
[root@localhost 桌面]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
200.0.0.0 192.168.8.100 255.255.255.0 UG 0 0 0 eth0
192.168.8.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
0.0.0.0 192.168.8.254 0.0.0.0 UG 0 0 0 eth0
[root@localhost 桌面]#

数据集介绍:野生动物与珍稀植物目标检测数据集一、基础信息数据集名称:野生动物与珍稀植物目标检测数据集数据规模:- 训练集:3,916张图片- 验证集:529张图片- 测试集:544张图片分类类别:- Bear(熊类): 野生动物监测重要目标- Bufo(蟾蜍类): 两栖动物生态研究关键物种- Deer(鹿类): 森林生态系统指示性动物- Heron(鹭类): 湿地环境监测典型鸟类- Iguana(鬣蜥类): 濒危爬行动物代表- PIG(猪类): 涵盖野生动物与养殖动物双重属性- Pulsatilla(白头翁属): 具有药用价值的珍稀植物- Snake(蛇类): 生物多样性研究重要组成部分- Urocissa(蓝鹊属): 特有鸟类保护研究对象标注格式:YOLO格式标准化标注,包含目标边界框与物种分类标签,适配目标检测模型训练。二、适用场景生态监测系统开发:支持构建森林/湿地生态智能监测系统,实现野生动物自动识别与种群统计。农业智能管理:应用于养殖场动物行为分析系统,辅助牲畜健康监测与异常行为预警。生物多样性研究:为濒危物种保护研究提供标注数据支撑,助力野外调查与栖息地保护。自然保护区监测:集成至红外相机影像分析系统,实现保护区内动植物自动识别与分类统计。三、数据集优势物种多样性突出:涵盖9大类陆生/水生动物及珍稀植物,包含濒危物种(如鬣蜥)与常见物种的平衡组合。多场景适应性:包含地面拍摄与可能存在的航拍视角(基于分类标签推断),适配不同监测设备需求。标注质量保障:经专业生态学者校验的物种分类标签,确保动物/植物分类准确性。科研与产业双适配:同时支持学术研究(生物多样性分析)与产业应用(农业/林业智能监测系统开发)。多任务扩展性:基于YOLO格式标注可直接应用于目标检测任务,支持扩展至物种分类、密度估计
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值