Aliyun 阿里云 ECS 服务器多公网 IP 无法连接问题半年未修复,仍然需要用户自己添加路由,体验感差,有些售后工程师不专业

体验感不好

有些售后工程师不专业

必须确保下方的 rc-local.service 可以正常开机自启

添加路由

ip -4 route add default via 10.0.0.253 dev eth1 table 200
ip -4 rule add from 10.0.0.2 lookup 200

在 /etc/rc.local 中添加路由,用于开机自启

echo "ip -4 route add default via 10.0.0.253 dev eth1 table 200" >> /etc/rc.local
echo "ip -4 rule add from 10.0.0.2 lookup 200 " >> /etc/rc.local
sudo chmod +x /etc/rc.local

需要在第一行添加 #!/bin/sh(直接运行阿里云给的命令不行,因为有些系统之前没有 /etc/rc.local 文件)

root@qd:~# cat /etc/rc.local
#!/bin/sh

ip -4 route add default via 10.0.0.253 dev eth1 table 200
ip -4 rule add from 10.0.0.2 lookup 200 
root@qd:~# 

查看服务 rc-local.service 配置

有些系统中 rc-local.service 文件没有 [Install] 相关内容,需要手动添加

root@qd:~# cat /usr/lib/systemd/system/rc-local.service
#  SPDX-License-Identifier: LGPL-2.1-or-later
#
#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation; either version 2.1 of the License, or
#  (at your option) any later version.

# This unit gets pulled automatically into multi-user.target by
# systemd-rc-local-generator if /etc/rc.local is executable.
[Unit]
Description=/etc/rc.local Compatibility
Documentation=man:systemd-rc-local-generator(8)
ConditionFileIsExecutable=/etc/rc.local
After=network.target

[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=infinity
RemainAfterExit=yes
GuessMainPID=no

[Install]
WantedBy=multi-user.target

root@qd:~# 

查看 rc-local.service 服务状态

重启 rc-local.service 服务:systemctl restart rc-local.service

查看 rc-local.service 服务状态:systemctl status rc-local.service

root@qd:~# systemctl status rc-local.service 
● rc-local.service - /etc/rc.local Compatibility
     Loaded: loaded (/usr/lib/systemd/system/rc-local.service; enabled; preset: enabled)
    Drop-In: /usr/lib/systemd/system/rc-local.service.d
             └─debian.conf
     Active: active (exited) since Fri 2026-07-24 17:48:28 CST; 1min 9s ago
 Invocation: 77b9dda855154704ae52a056bf5e383b
       Docs: man:systemd-rc-local-generator(8)
    Process: 870 ExecStart=/etc/rc.local start (code=exited, status=0/SUCCESS)
   Mem peak: 1.8M
        CPU: 23ms

Jul 24 17:48:28 qd systemd[1]: Starting rc-local.service - /etc/rc.local Compatibility...
Jul 24 17:48:28 qd systemd[1]: Started rc-local.service - /etc/rc.local Compatibility.
root@qd:~# 

设置开机自启

sudo systemctl enable rc-local