首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >路由网络通信

路由网络通信
EN

Ask Ubuntu用户
提问于 2018-04-16 12:15:43
回答 1查看 55关注 0票数 0

嗨,我试着做以下几件事(Ips就是例子):

  • 我有源计算机,IP 50.50.50.1
  • 我有目标计算机IP 50.50.40.1 (它无法从源计算机访问)
  • 我有带有IP 50.50.30.1的网关计算机(它可以从源计算机访问,并且通过网络适配器tun0连接到目标计算机)。

沟通应如下所示:

50.50.50.1 (default adapter) -> 50.50.40.1 (tun0 adapter) -> 50.50.30.1

在网关计算机的路由表中可以配置这样的东西吗?

我用的是ubuntu 16.04

谢谢你的回答

EN

回答 1

Ask Ubuntu用户

发布于 2018-04-17 11:57:21

我找到了解决办法。我可以使用NAT表:

代码语言:javascript
复制
# the ip of node which is in MSD network. This can be for example edge node
IP_OF_SOURCE_NODE=50.50.50.1
# ip of destination database where we want to connect (do not forget on port)
IP_OF_DESTINATION_NODE=50.50.30.1:22
# ip address of VPN network adapter
IP_OF_VPN_NETWORK_ADAPTER=50.50.51.1

# Need to change the destination ip to database ip for the packets incoming from default network from specific source (for example dge node) 
iptables -t nat -A PREROUTING -i ens5 -p tcp -s ${IP_OF_SOURCE_NODE} --dport 22 -j DNAT --to-destination ${IP_OF_DESTINATION_DATABASE}

# Need to change the source ip to inet address of vpn network address for packets leaving VPN network adapter
iptables -t nat -A POSTROUTING -o tun0 -p tcp -s ${IP_OF_SOURCE_NODE} --dport 22 -j SNAT --to-source ${IP_OF_VPN_NETWORK_ADAPTER}

之后,我成功地连接到节点50.50.30.1,从50.50.50.1到50.50.40.1。

票数 0
EN
页面原文内容由Ask Ubuntu提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://askubuntu.com/questions/1025506

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档