Oracle Cloud 设定 80及443 port

更多相关连结: https://linktr.ee/wade3c


Virtual Cloud Networks

需要先将防火墙上的port给打开

Iptable

有些port并不需要特别设定iptable中的route, ex: 3001, 9443

Check Drop or not

先去检查有没有被oracle image给block掉

sudo vim /etc/iptables/rules.v4

如果有被block会有这几行

-A InstanceServices -d 169.254.0.2/32 -p tcp -m tcp --dport 80 -m comment --comment "See the Oracle-Provided Images section in the Oracle Cloud Infrastructure documentation for security impact of modifying or removing this rule" -j ACCEPT
-A InstanceServices -d 169.254.169.254/32 -p tcp -m tcp --dport 80 -m comment --comment "See the Oracle-Provided Images section in the Oracle Cloud Infrastructure documentation for security impact of modifying or removing this rule" -j ACCEPT
-A InstanceServices -d 169.254.0.4/32 -p tcp -m tcp --dport 80 -m comment --comment "See the Oracle-Provided Images section in the Oracle Cloud Infrastructure documentation for security impact of modifying or removing this rule" -j ACCEPT

要把它删掉或是注解掉

如果注解掉后outbound还是有问题可以再注解掉

-A INPUT -j REJECT --reject-with icmp-host-prohibited

Set Routing

设定对应要route的port (inbound部分即可)

iptables -A INPUT -i ens3 -p tcp --dport 80 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A INPUT -i ens3 -p tcp --dport 443 -m state --state NEW,ESTABLISHED -j ACCEPT

把设定永久存下来的方式有两种可以选

把iptable的情况直接写入档案内
iptables-save > /etc/iptables/rules.v4
透过指令存
sudo netfilter-persistent save

这个指令会append全部生效的rules进档案所以会造成大量重複,请小心使用

Weird Bug

curl http://193.123.249.245curl: (7) Failed to connect to 193.123.249.245 port 80: No route to host

如果用docker开的80 port照上面可以通过,但是改用本机装的nginx就不行

但是在VM内用curl localhost/ private ip都会正常,直接把iptables关掉也还是会有一样的问题

https://stackoverflow.com/questions/71239321/oraclecloud-ubuntu20-connection-refused

https://stackoverflow.com/questions/67655725/python-fastapi-gunicorn-nginx-oracle-cloud-vm-website-not-showing

解法可以是用flush的方式把oracle cloud设的rules都给清掉

或是把刚刚input routing地方的source给修改一下 (可以当成一条新的rule)

-I INPUT -p tcp -s 0.0.0.0/0 --dport 80 -j ACCEPT

Reference

[OCI]Create Http Server Port On Oracle Cloud Instance

Opening port 80 on Oracle Cloud Infrastructure Compute node

When Oracle Cloud’s Ubuntu instance doesn’t accept connections to ports other than 22

Iptables to Oracle Cloud port 80 and 443 open


关于作者: 网站小编

码农网专注IT技术教程资源分享平台,学习资源下载网站,58码农网包含计算机技术、网站程序源码下载、编程技术论坛、互联网资源下载等产品服务,提供原创、优质、完整内容的专业码农交流分享平台。

热门文章