【Linux网络配置实战】服务器Network静态路由配置

简介: 【Linux网络配置实战】服务器Network静态路由配置

一、环境介绍

1.环境规划

hostname IP地址 网关 系统版本
server01 192.168.20.66 192.168.20.1 centos7.6
route01 192.168.20.254/24-172.16.10.254/24 centos7.6
server02 172.16.10.66 172.16.10.1 centos7.6

2.实验目的

server02与server01可以互通

二、检查各节点IP地址

1.检查server01服务器上

[root@server01 ~]# ifconfig 
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.20.66  netmask 255.255.255.0  broadcast 192.168.20.255
        inet6 fe80::2a6e:d4ff:fe89:5da4  prefixlen 64  scopeid 0x20<link>
        ether 28:6e:d4:89:5d:a4  txqueuelen 1000  (Ethernet)
        RX packets 6020  bytes 682748 (666.7 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 112  bytes 17061 (16.6 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 4  bytes 344 (344.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 4  bytes 344 (344.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        

2.检查server02服务器网卡

[root@server02 ~]# ifconfig 
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.16.10.66  netmask 255.255.255.0  broadcast 172.16.10.255
        inet6 fe80::2a6e:d4ff:fe89:cc37  prefixlen 64  scopeid 0x20<link>
        ether 28:6e:d4:89:cc:37  txqueuelen 1000  (Ethernet)
        RX packets 6030  bytes 686378 (670.2 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 107  bytes 16548 (16.1 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 4  bytes 344 (344.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 4  bytes 344 (344.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0


3.检查route01上的网卡


[root@route01 ~]# ifconfig 
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.20.254  netmask 255.255.255.0  broadcast 192.168.20.255
        inet6 fe80::2a6e:d4ff:fe89:7954  prefixlen 64  scopeid 0x20<link>
        ether 28:6e:d4:89:79:54  txqueuelen 1000  (Ethernet)
        RX packets 5762  bytes 655197 (639.8 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 117  bytes 17132 (16.7 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.16.10.254  netmask 255.255.255.0  broadcast 172.16.10.255
        inet6 fe80::2a6e:d4ff:fe89:d1a0  prefixlen 64  scopeid 0x20<link>
        ether 28:6e:d4:89:d1:a0  txqueuelen 1000  (Ethernet)
        RX packets 3012  bytes 349027 (340.8 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 23  bytes 1499 (1.4 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 12  bytes 1040 (1.0 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 12  bytes 1040 (1.0 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0



三、在route01上启动IP包转发

[root@route01 ~]# cd /proc/sys/net/ipv4/
[root@route01 ipv4]# echo 1 > /proc/sys/net/ipv4/ip_forward
[root@route01 ipv4]# 

四、查看当前两节点互通情况

1.查看server01和server02连通状态

image.png

image.png

2.查看当前server01路由表

[root@server01 ~]# route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         gateway         0.0.0.0         UG    0      0        0 eth0
link-local      0.0.0.0         255.255.0.0     U     1002   0        0 eth0
192.168.20.0    0.0.0.0         255.255.255.0   U     0      0        0 eth0

3.查看当前server01路由表

[root@server02 ~]# route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         gateway         0.0.0.0         UG    0      0        0 eth0
link-local      0.0.0.0         255.255.0.0     U     1002   0        0 eth0
172.16.10.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0

五、在server01配置静态路由

1.添加静态路由

[root@server01 ~]# route add -net 172.16.10.0/24 gw 192.168.20.254

2.查看当前路由表

[root@server01 ~]# route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         gateway         0.0.0.0         UG    0      0        0 eth0
link-local      0.0.0.0         255.255.0.0     U     1002   0        0 eth0
172.16.10.0     192.168.20.254  255.255.255.0   UG    0      0        0 eth0
192.168.20.0    0.0.0.0         255.255.255.0   U     0      0        0 eth0

六、在server02配置静态路由

1.添加静态路由

[root@server02 ~]# route add -net 192.168.20.0/24 gw 172.16.10.254

2.查看当前路由表

[root@server02 ~]# route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         gateway         0.0.0.0         UG    0      0        0 eth0
link-local      0.0.0.0         255.255.0.0     U     1002   0        0 eth0
172.16.10.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0
192.168.20.0    172.16.10.254   255.255.255.0   UG    0      0        0 eth0

七、检查server01和server02连通情况

image.png

image.png

八、server01配置永久路由

1.在server01上删除临时静态路由

[root@server01 ~]# route delete -net 172.16.10.0/24
[root@server01 ~]# route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         gateway         0.0.0.0         UG    0      0        0 eth0
link-local      0.0.0.0         255.255.0.0     U     1002   0        0 eth0
192.168.20.0    0.0.0.0         255.255.255.0   U     0      0        0 eth0

2.新增网卡配置文件写入路由

[root@server01 ~]# !73
cd /etc/sysconfig/network-scripts/
[root@server01 network-scripts]# vim route-eth0
[root@server01 network-scripts]# cat route-eth0 
172.16.10.0/24 via 192.168.20.254

3.重启网路服务

[root@server01 network-scripts]# service network restart 
Restarting network (via systemctl):                        [  OK  ]

4.查看路由状态

[root@server01 network-scripts]# route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         gateway         0.0.0.0         UG    0      0        0 eth0
link-local      0.0.0.0         255.255.0.0     U     1002   0        0 eth0
172.16.10.0     192.168.20.254  255.255.255.0   UG    0      0        0 eth0
192.168.20.0    0.0.0.0         255.255.255.0   U     0      0        0 eth0

九、server02配置永久静态路由

1.删除临时静态路由

route delete -net 192.168.20.0/24    # 删除临时路由
cd /etc/sysconfig/network-scripts/    # 进入网卡配置文件目录

2.新增网卡配置文件写入路由

[root@server02 network-scripts]# vim route-eth1
[root@server02 network-scripts]# cat route-eth1
192.168.20.0/24 via 172.16.10.254

3.重启网络

[root@server02 network-scripts]# service network restart 
Restarting network (via systemctl):                        [  OK  ]

4.查看静态路由表

[root@server02 network-scripts]# route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         gateway         0.0.0.0         UG    100    0        0 eth0
172.16.10.0     0.0.0.0         255.255.255.0   U     100    0        0 eth0
192.168.20.0    172.16.10.254   255.255.255.0   UG    100    0        0 eth0

十、测试server01与server02互通情况

image.png

image.png

相关文章
|
14天前
|
监控 Linux Shell
|
16天前
|
监控 Java Linux
Linux系统之安装Ward服务器监控工具
【10月更文挑战第17天】Linux系统之安装Ward服务器监控工具
38 5
Linux系统之安装Ward服务器监控工具
|
5天前
|
PHP 数据库 数据安全/隐私保护
布谷直播源码部署服务器关于数据库配置的详细说明
布谷直播系统源码搭建部署时数据库配置明细!
|
4天前
|
缓存 Unix Linux
服务器linux!!!
本文介绍了计算机的演变历史、硬件基础知识及服务器相关知识。从电子管时代的ENIAC到冯-诺伊曼架构,再到现代计算机系统组成,详细讲解了计算机的发展历程。此外,文章还介绍了服务器的分类、品牌、硬件组成以及IDC机房的上架流程,为读者提供了全面的技术背景知识。
19 0
服务器linux!!!
|
6天前
|
人工智能 安全 Linux
|
9天前
|
Linux 数据库
Linux服务如何实现服务器重启后的服务延迟自启动?
【10月更文挑战第25天】Linux服务如何实现服务器重启后的服务延迟自启动?
45 3
|
12天前
|
存储 安全 关系型数据库
Linux系统在服务器领域的应用与优势###
本文深入探讨了Linux操作系统在服务器领域的广泛应用及其显著优势。通过分析其开源性、安全性、稳定性和高效性,揭示了为何Linux成为众多企业和开发者的首选服务器操作系统。文章还列举了Linux在服务器管理、性能优化和社区支持等方面的具体优势,为读者提供了全面而深入的理解。 ###
|
14天前
|
关系型数据库 MySQL Linux
基于阿里云服务器Linux系统安装Docker完整图文教程(附部署开源项目)
基于阿里云服务器Linux系统安装Docker完整图文教程(附部署开源项目)
139 2
|
14天前
|
NoSQL Linux PHP
|
4天前
|
弹性计算
阿里云2核16G服务器多少钱一年?亲测价格查询1个月和1小时收费标准
阿里云2核16G服务器提供多种ECS实例规格,内存型r8i实例1年6折优惠价为1901元,按月收费334.19元,按小时收费0.696221元。更多规格及详细报价请访问阿里云ECS页面。
37 9