前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >【Linux网络配置实战】服务器Network静态路由配置

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

原创
作者头像
江湖有缘
发布2023-09-25 12:24:01
1.3K0
发布2023-09-25 12:24:01
举报
文章被收录于专栏:Linux成长之路

一、环境介绍

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服务器上

代码语言:shell
复制
[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服务器网卡

代码语言:shell
复制
[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上的网卡

代码语言:shell
复制
[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包转发

代码语言:shell
复制
[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
image.png
image.png

2.查看当前server01路由表

代码语言:shell
复制
[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路由表

代码语言:shell
复制
[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.添加静态路由

代码语言:shell
复制
[root@server01 ~]# route add -net 172.16.10.0/24 gw 192.168.20.254

2.查看当前路由表

代码语言:shell
复制
[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.添加静态路由

代码语言:shell
复制
[root@server02 ~]# route add -net 192.168.20.0/24 gw 172.16.10.254

2.查看当前路由表

代码语言:shell
复制
[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
image.png
image.png

八、server01配置永久路由

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

代码语言:shell
复制
[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.新增网卡配置文件写入路由

代码语言:shell
复制
[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.重启网路服务

代码语言:shell
复制
[root@server01 network-scripts]# service network restart 
Restarting network (via systemctl):                        [  OK  ]

4.查看路由状态

代码语言:shell
复制
[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.删除临时静态路由

代码语言:shell
复制
route delete -net 192.168.20.0/24    # 删除临时路由
cd /etc/sysconfig/network-scripts/    # 进入网卡配置文件目录

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

代码语言:shell
复制
[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.重启网络

代码语言:shell
复制
[root@server02 network-scripts]# service network restart 
Restarting network (via systemctl):                        [  OK  ]

4.查看静态路由表

代码语言:shell
复制
[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
image.png
image.png

我正在参与2023腾讯技术创作特训营第二期有奖征文,瓜分万元奖池和键盘手表

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 一、环境介绍
    • 1.环境规划
      • 2.实验目的
      • 二、检查各节点IP地址
        • 1.检查server01服务器上
          • 2.检查server02服务器网卡
            • 3.检查route01上的网卡
            • 三、在route01上启动IP包转发
            • 四、查看当前两节点互通情况
              • 1.查看server01和server02连通状态
                • 2.查看当前server01路由表
                  • 3.查看当前server01路由表
                  • 五、在server01配置静态路由
                    • 1.添加静态路由
                      • 2.查看当前路由表
                      • 六、在server02配置静态路由
                        • 1.添加静态路由
                          • 2.查看当前路由表
                          • 七、检查server01和server02连通情况
                          • 八、server01配置永久路由
                            • 1.在server01上删除临时静态路由
                              • 2.新增网卡配置文件写入路由
                                • 3.重启网路服务
                                  • 4.查看路由状态
                                  • 九、server02配置永久静态路由
                                    • 1.删除临时静态路由
                                      • 2.新增网卡配置文件写入路由
                                        • 3.重启网络
                                          • 4.查看静态路由表
                                          • 十、测试server01与server02互通情况
                                          相关产品与服务
                                          云服务器
                                          云服务器(Cloud Virtual Machine,CVM)提供安全可靠的弹性计算服务。 您可以实时扩展或缩减计算资源,适应变化的业务需求,并只需按实际使用的资源计费。使用 CVM 可以极大降低您的软硬件采购成本,简化 IT 运维工作。
                                          领券
                                          问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档