# Oracle 服务器无法访问22以外端口的解决教程 在使用 Oracle 云服务器时,常遇到除了 SSH(22端口)以外的端口无法访问的情况。本文教你如何排查和解决此问题。 --- ## 一、问题表现 - 服务器可以正常通过 SSH 端口 22 登录 - 但其他端口(如 80、443、或者自定义端口)无法访问 --- ## 二、排查步骤 ### 1. 检查 Oracle 云安全组设置 Oracle 云服务器默认会绑定安全组,安全组中对入站规则有限制。默认只允许 22 端口。 **步骤:** - 登录 Oracle 云控制台 - 找到对应的实例,查看关联的安全组 - 检查“入站规则”,确保需要开放的端口已添加(如80、443、3306等) - 如果没有,点击添加,开放对应端口的入站访问权限 > **示例:** > > - 添加端口 80 TCP,允许所有来源 0.0.0.0/0 > - 添加端口 443 TCP,同上 > - 也可以直接添加所有协议,来源允许所有来源 0.0.0.0/0 > > 这是最常见导致端口无法访问的原因,请务必先检查安全组设置。 --- ### 2. 配置服务器内部的防火墙规则(iptables) 即使安全组放开了端口,服务器内的 iptables 规则也可能限制访问。 #### 2.1 查看当前 iptables 规则 ```bash sudo iptables -L -n -v ``` > **示例反馈(部分):** ``` Chain INPUT (policy ACCEPT 0 packets, 0 bytes) pkts bytes target prot opt in out source destination 8064 14M ACCEPT 0 -- * * 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED 19 972 ACCEPT 6 -- * * 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:22 644 30966 REJECT 0 -- * * 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited ``` 这里可以看到只有 SSH 端口22有明确放行,其他流量可能被 REJECT。 --- #### 2.2 清空所有 iptables 规则,允许所有端口访问(测试用) **执行命令:** ```bash sudo iptables -F sudo iptables -X sudo iptables -t nat -F sudo iptables -t nat -X sudo iptables -t mangle -F sudo iptables -t mangle -X sudo iptables -t raw -F sudo iptables -t raw -X sudo iptables -P INPUT ACCEPT sudo iptables -P FORWARD ACCEPT sudo iptables -P OUTPUT ACCEPT ``` #### 2.3 查看清空后的规则确认 ```bash sudo iptables -L -n -v ``` **示例反馈:** ``` Chain INPUT (policy ACCEPT 166 packets, 11487 bytes) pkts bytes target prot opt in out source destination Chain FORWARD (policy ACCEPT 0 packets, 0 bytes) pkts bytes target prot opt in out source destination Chain OUTPUT (policy ACCEPT 136 packets, 10343 bytes) pkts bytes target prot opt in out source destination ``` --- #### 2.4 保存规则,确保重启后生效 Ubuntu 下可以用 `iptables-persistent` 来保存规则。 1. 安装: ```bash sudo apt update sudo apt install iptables-persistent ``` 安装过程中会提示保存现有规则,选择“是”。 2. 手动保存当前规则: ```bash sudo iptables-save > /etc/iptables/rules.v4 ``` 3. 重启服务器后,使用 ```bash sudo iptables -L -n -v ``` 确认规则依然是放行所有的。 --- ## 三、总结 - **第一步**:确保 Oracle 云安全组中开放了你需要的端口(入站规则)。 - **第二步**:检查并调整服务器内部的 iptables 规则,避免被防火墙阻挡。 - **第三步**:保存 iptables 规则,保证重启后依旧生效。 --- 祝你服务器端口畅通无阻! --- ## 附录:常用命令汇总 | 命令 | 说明 | |---------------------------------|--------------------------| | `sudo iptables -L -n -v` | 查看当前防火墙规则 | | `sudo iptables -F` | 清空 filter 表规则 | | `sudo iptables -X` | 删除自定义链 | | `sudo iptables -t nat -F` | 清空 nat 表规则 | | `sudo iptables -t nat -X` | 删除 nat 自定义链 | | `sudo iptables -P INPUT ACCEPT` | 设置默认输入链策略为 ACCEPT | | `sudo iptables-save > /etc/iptables/rules.v4` | 保存当前规则 | | `sudo apt install iptables-persistent` | 安装规则持久化工具 | --- 完全免费社工库 下山虎社工库 https://t.me/MTTigerSGK #社工库 #免费社工库
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up