Quantcast
Channel: CodeSection,代码区,Linux操作系统:Ubuntu_Centos_Debian - CodeSec
Viewing all articles
Browse latest Browse all 11063

网络的路由配置以及Centos7的网络组实现

$
0
0
1、路由配置

路由是互联网络的核心,没有路由的网络如同一座孤岛,掌握路由的配置是IT人员的必备技能。

例如:现在有三台主机需要通信,其中A和B在同一网段,C在另一网段,这两个网段有三个路由相隔,如何实现他们之间的通信呢?


网络的路由配置以及Centos7的网络组实现

主机A:IP=192.168.1.100/24

主机B:IP=192.168.1.63/24

主机C:IP=10.2.110.100/16

R1的接口0:IP=192.168.1.1/24,接口1:IP=110.1.24.10/24

R2的接口0:IP=110.1.24.20/24,接口1:IP=72.98.2.10/16

R3的接口0:IP=72.98.70.20/16,接口1:IP=10.2.0.1/16

通过分析上面的网络环境,可以得到R1,R2和R3的路由信息,这里我们指定每一个路由的静态路由表

R1:路由表

网段 网关接口

192.168.1.0/24 0.0.0.0/0 eth0

110.1.24.10/24 0.0.0.0/0 eth1

72.98.0.0/16 110.1.24.20 eth1

10.2.0.0/16 110.1.24.20 eth1

0.0.0.0/0 110.1.24.20 eth1

R2:路由表

网段 网关接口

192.168.1.0/24 110.1.24.10 eth0

110.1.24.10/24 0.0.0.0/0 eth0

72.98.0.0/16 0.0.0.0/0 eth1

10.2.0.0/16 72.98.70.20 eth1

0.0.0.0/0 外网IP(这里不写)

R3:路由表

网段 网关接口

192.168.1.0/24 72.98.2.10 eth0

110.1.24.10/24 72.98.2.10 eth0

72.98.0.0/16 0.0.0.0/0 eth0

10.2.0.0/16 0.0.0.0/0 eth1

0.0.0.0/0 72.98.2.10 eth0

这里用3台centos系统作为路由

用node1主机来做route1

[root@node1 ~]# ip addr show dev eth1 3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:0c:29:e2:96:7c brd ff:ff:ff:ff:ff:ff inet 192.168.1.1/24 scope global eth1 inet6 fe80::20c:29ff:fee2:967c/64 scope link valid_lft forever preferred_lft forever [root@node1 ~]# ip addr show dev eth2 4: eth2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:0c:29:e2:96:86 brd ff:ff:ff:ff:ff:ff inet 110.1.24.10/24 scope global eth2 inet6 fe80::20c:29ff:fee2:9686/64 scope link valid_lft forever preferred_lft forever [root@node1 ~]# route add -net 10.2.0.0/16 gw 110.1.24.20 dev eth2 [root@node1 ~]# route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1 110.1.24.0 0.0.0.0 255.255.255.0 U 0 0 0 eth2 10.2.0.0 110.1.24.20 255.255.0.0 UG 0 0 0 eth2 72.98.0.0 110.1.24.20 255.255.0.0 UG 0 0 0 eth2 10.1.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0 169.254.0.0 0.0.0.0 255.255.0.0 U 1002 0 [root@node1 ~]# echo 1 > /proc/sys/net/ipv4/ip_forward

note2用来做route2

[root@node2 ~]# ip addr add 110.1.24.20/24 dev eth1 [root@node2 ~]# ip addr add 72.98.2.10/16 dev eth2 [root@node2 ~]# ip addr show dev eth1 3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:0c:29:00:90:24 brd ff:ff:ff:ff:ff:ff inet 110.1.24.20/24 scope global eth1 inet6 fe80::20c:29ff:fe00:9024/64 scope link valid_lft forever preferred_lft forever [root@node2 ~]# ip addr show dev eth2 4: eth2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:0c:29:00:90:2e brd ff:ff:ff:ff:ff:ff inet 72.98.2.10/16 scope global eth2 inet6 fe80::20c:29ff:fe00:902e/64 scope link valid_lft forever preferred_lft forever [root@node2 ~]# route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 110.1.24.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1 72.98.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth2 10.1.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0 169.254.0.0 0.0.0.0 255.255.0.0 U 1002 0 0 eth0 169.254.0.0 0.0.0.0 255.255.0.0 U 1003 0 0 eth1 [root@node2 ~]# route add -net 192.168.1.0/24 gw 110.1.24.10 dev eth1 [root@node2 ~]# route add -net 10.2.0.0/16 gw 72.98.70.20 dev eth2 [root@node2 ~]# route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 192.168.1.0 110.1.24.10 255.255.255.0 UG 0 0 0 eth1 110.1.24.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1 10.2.0.0 72.98.70.20 255.255.0.0 UG 0 0 0 eth2 72.98.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth2 10.1.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0 169.254.0.0 0.0.0.0 255.255.0.0 U 1002 0 0 eth0 169.254.0.0 0.0.0.0 255.255.0.0 U 1003 0 0 eth1 [root@node2 ~]# echo 1 > /proc/sys/net/ipv4/ip_forward

note3用来做route3

[root@node3 ~]# ip addr add 72.98.70.20/16 dev eth1 [root@node3 ~]# ip addr add 10.2.0.1/16 dev eth2 [root@node3 ~]# ip addr show dev eth1 3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:0c:29:47:d8:e1 brd ff:ff:ff:ff:ff:ff inet 72.98.70.20/16 scope global eth1 inet6 fe80::20c:29ff:fe47:d8e1/64 scope link valid_lft forever preferred_lft forever [root@node3 ~]# ip addr show dev eth2 4: eth2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:0c:29:47:d8:eb brd ff:ff:ff:ff:ff:ff inet 10.2.0.1/16 scope global eth2 inet6 fe80::20c:29ff:fe47:d8eb/64 scope link valid_lft forever preferred_lft forever [root@node3 ~]# route add -net 110.1.24.0/24 gw 72.98.2.10 dev eth1 [root@node3 ~]# route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 192.168.1.0 72.98.2.10 255.255.255.0 UG 0 0 0 eth1 110.1.24.0 72.98.2.10 255.255.255.0 UG 0 0 0 eth1 10.2.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth2 72.98.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth1 10.1.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0 169.254.0.0 0.0.0.0 255.255.0.0 U 1002 0 0 eth0 169.254.0.0 0.0.0.0 255.255.0.0 U 1003 0 0 eth1 [root@node3 ~]# echo 1 > /proc/sys/net/ipv4/ip_forward

主机A:

[root@host1 ~]# ip addr add 192.168.1.100/24 dev eno33554984 [root@host1 ~]# ip route add default via 192.168.1.1 [root@host1 ~]# ip addr show dev eno33554984 3: eno33554984: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:0c:29:2b:82:a6 brd ff:ff:ff:ff:ff:ff inet 192.168.1.100/24 scope global eno33554984 valid_lft forever preferred_lft forever inet6 fe80::20c:29ff:fe2b:82a6/64 scope link valid_lft forever preferred_lft forever [root@host1 ~]# route -n -bash: route: command not found [root@host1 ~]# ip route show 10.1.0.0/16 dev eno16777736 proto kernel scope link src 10.1.70.171 metric 100 192.168.1.0/24 dev eno33554984 proto kernel scope link src 192.168.1.100 0.0.0.0 via 192.168.1.1 dev eno33554984

主机B:

[root@host2 ~]# ip addr show dev eno33554984 3: eno33554984: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:0c:29:aa:22:47 brd ff:ff:ff:ff:ff:ff inet 192.168.1.63/24 scope global eno33554984

Viewing all articles
Browse latest Browse all 11063

Trending Articles