您的 Travis 作业在功能齐全的 Linux 环境中运行,其中包括使用iptables命令创建防火墙规则的能力。考虑这个非常简单的.travis.yml文件:
---
script:
- curl http://icanhazip.com
Run Code Online (Sandbox Code Playgroud)
把它放在一个存储库中并运行它,它会工作得很好:
$ curl http://icanhazip.com
104.196.57.92
The command "curl http://icanhazip.com" exited with 0.
Run Code Online (Sandbox Code Playgroud)
为了模拟离线行为,我们只需添加一个防火墙规则来阻止端口 80 上的出站访问:
---
script:
- sudo iptables -A OUTPUT -p tcp --dport 80 -j REJECT
- curl http://icanhazip.com
Run Code Online (Sandbox Code Playgroud)
这将失败:
$ curl http://icanhazip.com
curl: (7) Failed to connect to icanhazip.com port 80: Connection refused
The command "curl http://icanhazip.com" exited with 7.
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
309 次 |
| 最近记录: |