AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / user-316207

Ondra Sniper Flidr's questions

Martin Hope
Ondra Sniper Flidr
Asked: 2016-07-15 07:01:18 +0800 CST

跨 VPC 对等使用来自不同 VPC 的 AWS Nat Gateway

  • 2

我想使用来自另一个 VPC 的 Nat 网关(不是 EC2 上的 Nat 实例!)将我的流量从对等 VPC 路由到 Internet。我的基础架构如下所示:

/---------------------VPC-LIVECHAT---------------------\
| /---Subnet A---\  /---Subnet B---\  /---Subnet C---\ |
| |              |  |              |  |              | |
| \-10.10.0.0/24-/  \-10.10.1.0/24-/  \-10.10.2.0/24-/ |
\------------------------------------------------------/
               |                        |
               | VPC Peering Connection |
               |                        |
/----------------------VPC-COMMON----------------------\
| /---Subnet A---\  /---Subnet B---\  /---Subnet C---\ |
| |  /--------\  |  |  /--------\  |  |  /--------\  | |
| |  | NAT GW |  |  |  | NAT GW |  |  |  | NAT GW |  | |
| |  \--------/  |  |  \--------/  |  |  \--------/  | |
| \-10.10.3.0/24-/  \-10.10.4.0/24-/  \-10.10.5.0/24-/ |
\------------------------------------------------------/
               |                        |
               | VPC Peering Connection |
               |                        |
/---------------------VPC-DATABASE---------------------\
| /---Subnet A---\  /---Subnet B---\  /---Subnet C---\ |
| |              |  |              |  |              | |
| \-10.10.6.0/24-/  \-10.10.7.0/24-/  \-10.10.8.0/24-/ |
\------------------------------------------------------/

我的想法:

  • 我将在每个子网中设置具有子网和 Nat 网关的 VPC-COMMON(每个 AZ 一个子网)
  • 我将设置 VPC-LIVECHAT 和 VPC-DATABASE VPC,创建 VPC 对等连接
  • 在 VPC-COMMON 子网中,路由 0.0.0.0/0 -> Nat Gateway 在同一子网中
  • 在 VPC-LIVECHAT 和 VPC-DATABASE 子网(全部)中,将有路由 VPC-COMMON CIDR -> VPC 对等连接
  • 在 VPC-LIVECHAT 和 VPC-DATABASE 的每个子网中,都会有路由 0.0.0.0/ -> 在 VPC-COMMON 的相应子网中的 Nat 网关(子网 A 将使用 VPC-COMMON 子网 A 中的 NAT GW 等等...)

我认为这个设置应该工作得很好,它只是路由 VLAN。但不是在 AWS 中。AWS 不想让我在路由表中的不同 VPC 中使用 Nat Gateway,但出现错误

“路由表 rtb-293fa54d 和接口 interface-c2002e9e 属于不同的网络”

我也不能在 AWS 中使用 Nat Gateway 的私有 IP,AWS 不支持路由目标中的 IP 地址(我真的很想知道为什么)。

我正在使用 CloudFormation,我的路由定义如下所示:

"RoutePrivate3ToNatInCommon" : {
    "Type" : "AWS::EC2::Route",
    "Condition" : "IsNotVpcCommon",
    "Properties" : {
        "DestinationCidrBlock" : "0.0.0.0/0",
        "RouteTableId" : { "Ref" : "PrivateSubnet3RoutingTable" },
        "NatGatewayId" : { "Fn::GetAtt" : [ "NatGatewaySettingsForNotCommon", "NatGatewayAZC" ] }
    }
}

NatGatewaySettingForNotCommon 是我的自定义 lambda 支持资源,可帮助我获取每个可用区的 Nat 网关列表。

有什么办法可以实现这个设置?我每个区域将有大约 10 个 VPC,每个区域有 3 个私有子网,我真的不想设置(并支付)30 个 Nat 网关。这看起来像常规的“非多云”网络设置,因此在云中实现它应该没有问题。或者是吗?

routing amazon-web-services amazon-vpc vpc-peering amazon-nat-gateway
  • 1 个回答
  • 5287 Views
Martin Hope
Ondra Sniper Flidr
Asked: 2016-03-05 01:36:07 +0800 CST

重定向到 iptables 中的另一个端口显示没有链错误

  • 0

我现在正面临 iptables 的奇怪问题。简单地说,我想将流量从端口 514 重定向到端口 5140。我正在使用这个 IPTables 命令来实现它:

iptables -t nat -A PREROUTING -p tcp --dport 514 -j REDIRECT --to-port 5140

但我仍然收到关于没有链条的错误

iptables: No chain/target/match by that name.

nat 表中肯定有 PREROUTING 链,这是 iptables -t nat -nL

root@VPS-LOGGER-TMP:~# iptables -t nat -nL
Chain PREROUTING (policy ACCEPT)
target     prot opt source               destination         

Chain INPUT (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         

Chain POSTROUTING (policy ACCEPT)
target     prot opt source               destination    

我正在使用 Debian Wheezy 并且我已经加载了所有需要的模块:

root@VPS-LOGGER-TMP:~# lsmod |grep nat
iptable_nat            12928  0 
nf_nat                 18242  1 iptable_nat
nf_conntrack_ipv4      14078  4 nf_nat,iptable_nat
nf_conntrack           52720  4 xt_state,nf_conntrack_ipv4,nf_nat,iptable_nat
ip_tables              22042  2 iptable_filter,iptable_nat
x_tables               19118  9 ip_tables,iptable_filter,xt_multiport,ip6_tables,ip6table_filter,xt_state,xt_tcpudp,ipt_REJECT,iptable_nat

你能告诉我我做错了什么吗?据我所知,这应该可以完美地工作。非常感谢。

iptables
  • 1 个回答
  • 260 Views
Martin Hope
Ondra Sniper Flidr
Asked: 2015-10-29 05:18:18 +0800 CST

Openvpn:客户端可以ping服务器,服务器无法ping客户端

  • 1

我在 AWS 和 GoGrid 数据中心之间设置 openvpn 时遇到了奇怪的问题。我的网络看起来像这样

/----------------\               /----------------\               /------------------\               /----------------\
|  VPS-DEVEL.gg  |               |    VPS-VPN.gg  |               |   VPS-VPN.aws    |               | VPS-PROVIS.aws |
| 10.160.64.7/24 | eth1 --- eth1 | 10.160.64.9/24 | tun0 --- tun0 | 10.160.48.219/24 | eth0 --- eth0 | 10.160.52.8/24 |
\----------------/               \----------------/               \------------------/               \----------------/

我可以毫无问题地从 aws ping 到 gogrid(来自两个 aws 虚拟机的 VPS-DEVEL.gg 和 VPS-VPN.gg),但我无法从 gogrid ping 到 AWS。

我在 VPS-VPN.gg 上的路由表如下所示:

[root@VPSVPN ~]# route -n
Směrovací tabulka v jádru pro IP
Adresát         Brána           Maska           Přízn Metrik Odkaz  Užt Rozhraní
169.254.4.1     164.40.132.83   255.255.255.255 UGH   0      0        0 eth0
169.254.4.2     10.160.64.9     255.255.255.255 UGH   0      0        0 eth1
10.8.0.2        0.0.0.0         255.255.255.255 UH    0      0        0 tun0
164.40.132.80   0.0.0.0         255.255.255.240 U     0      0        0 eth0
10.8.0.0        10.8.0.2        255.255.255.240 UG    0      0        0 tun0
10.159.254.0    10.160.64.1     255.255.255.0   UG    0      0        0 eth1
10.160.64.0     0.0.0.0         255.255.255.0   U     0      0        0 eth1
10.160.0.0      10.8.0.2        255.255.192.0   UG    0      0        0 tun0
0.0.0.0         164.40.132.81   0.0.0.0         UG    0      0        0 eth0

我在 VPS-VPN.aws 上的路由表:

admin@ip-10-160-48-219:~$ sudo route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         10.160.48.1     0.0.0.0         UG    0      0        0 eth0
10.8.0.0        10.8.0.9        255.255.255.240 UG    0      0        0 tun0
10.8.0.9        0.0.0.0         255.255.255.255 UH    0      0        0 tun0
10.160.48.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0
10.160.64.0     10.8.0.9        255.255.255.0   UG    0      0        0 tun0
169.254.0.0     0.0.0.0         255.255.0.0     U     0      0        0 eth0

我的 openvpn 服务器配置(gogrid 端):

[root@VPSVPN ~]# cat /etc/openvpn/server.conf
port 1194
proto udp
dev tun
ca ca.crt
cert vpsvpn.crt
key vpsvpn.key  # This file should be kept secret
dh dh1024.pem
server 10.8.0.0 255.255.255.240
ifconfig-pool-persist ipp.txt
client-config-dir /etc/openvpn/ccd # ghor
client-to-client # ghor
keepalive 10 120
comp-lzo
user nobody
group nobody
persist-key
persist-tun
max-clients 100
status /var/log/openvpn-status.log
log-append  /var/log/openvpn.log
verb 11
route 10.160.0.0 255.255.192.0
push "route 10.160.64.0 255.255.255.0"

我的 openvpn 客户端配置(aws 端):

admin@ip-10-160-48-219:~$ cat /etc/openvpn/gogrid/gogrid.ovpn 
client
dev tun
proto udp
remote 164.40.132.83 1194
resolv-retry infinite
nobind
persist-key
persist-tun
comp-lzo
verb 3
ca /etc/openvpn/gogrid/ca.crt
cert /etc/openvpn/gogrid/test-eu-west-1-aws.crt
key /etc/openvpn/gogrid/test-eu-west-1-aws.key
askpass /etc/openvpn/gogrid/test-eu-west-1-aws.pass

TCPDump 显示了这一点:

  1. 来自 aws(两个虚拟机)的 Ping 通过 VPS-VPN.aws tun0 接口进入 vpn 隧道,到达 VPS-VPN.gg 上的 tun0 并回复正确
  2. 来自 gogrid 的 Ping 通过 VPS-VPN.gg tun0 接口进入 vpn 隧道,但未到达 VPS-VPN.aws 上的 tun0 接口
  3. 从 VPS-VPN.gg ping 到 tun0 (10.8.0.10) 的 VPS-VPN.aws IP 运行良好

两个 VPS-VPN 都启用了 ip_forward。

VPS-VPN.aws 上的 IPTables 看起来像这样,AWS 安全组设置为允许来自任何地方的所有流量(当我可以在 VM 上使用 iptables 时,我不喜欢使用 SecGroups):

admin@ip-10-160-48-219:~$ sudo iptables -nvL
Chain INPUT (policy ACCEPT 867 packets, 68073 bytes)
 pkts bytes target        prot opt in     out     source            destination         
 1426  117K fail2ban-ssh  tcp  --  *      *       0.0.0.0/0         0.0.0.0/0            multiport dports 22

Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         
 1360  105K ACCEPT     all  --  *      *       0.0.0.0/0            0.0.0.0/0           

Chain OUTPUT (policy ACCEPT 743 packets, 72322 bytes)
 pkts bytes target     prot opt in     out     source               destination         

Chain fail2ban-ssh (1 references)
 pkts bytes target     prot opt in     out     source               destination         
 1400  115K RETURN     all  --  *      *       0.0.0.0/0            0.0.0.0/0          

admin@ip-10-160-48-219:~$ sudo iptables -t nat -nvL
Chain PREROUTING (policy ACCEPT 1743 packets, 105K bytes)
 pkts bytes target     prot opt in     out     source               destination         

Chain INPUT (policy ACCEPT 1359 packets, 69760 bytes)
 pkts bytes target     prot opt in     out     source               destination         

Chain OUTPUT (policy ACCEPT 390 packets, 40130 bytes)
 pkts bytes target     prot opt in     out     source               destination         

Chain POSTROUTING (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target      prot opt in     out     source              destination         
  748 67734 MASQUERADE  all  --  *      eth0    0.0.0.0/0           0.0.0.0/0           
   17  1428 MASQUERADE  all  --  *      tun0    0.0.0.0/0           0.0.0.0/0           

我在路由中使用 10.160.0.0/18 只是因为我将拥有更多具有此范围内子网的 VPC。每个 AWS VPC 都有子网 /21。一切都在 GoGrid 端的子网 10.160.64.0/24 中,并且 aws 路由表设置为将此子网的所有内容路由到 VPS-VPN.aws 实例。这是有效的,我可以从 AWS ping GoGrid。

你能指出我在哪里犯了一些错误吗?此设置 AFAIK 应该适用于两个方向。非常感谢。

linux
  • 1 个回答
  • 3513 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve