# Block network access of a test/process on Travis?

**URL:** <https://travis-ci.community/t/block-network-access-of-a-test-process-on-travis/7070>\
**Category:** Python\
**Created:** [January 31, 2020, 10:26am UTC](https://travis-ci.community/t/block-network-access-of-a-test-process-on-travis/7070 "2020-01-31T10:26:19Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![OliBarrington](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/olibarrington/32/3745_2.png) [@OliBarrington](https://travis-ci.community/u/OliBarrington)\
**Post date:** [January 31, 2020, 10:26am UTC](https://travis-ci.community/t/block-network-access-of-a-test-process-on-travis/7070/1 "2020-01-31T10:26:19Z")

</div>

Based on [this question](https://unix.stackexchange.com/q/68956/28301) and its answers: What is an applicable approach (if there is any) of blocking network access of a test or process on Travis CI?

Background: I want to test offline functionality, i.e. a cache, enabling to use a library without internet/network access. A dependency (a third-party piece of software) involved in the process tries to connect to the internet/network. Currently, I am managing to prohibit its internet/network access (confirmed locally by “pulling the plug”), though I want to find a way to implement a proper CI test for long-term maintenance. Most of the testing infrastructure is written in Python and based on pytest.

---

<div class="post-metadata">

**Author:** ![Montana](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/montana/32/9566_2.png) [@Montana](https://travis-ci.community/u/Montana)\
**Post date:** [January 31, 2020, 10:31am UTC](https://travis-ci.community/t/block-network-access-of-a-test-process-on-travis/7070/2 "2020-01-31T10:31:44Z")

</div>

Your Travis jobs run in a fully functional Linux env, which includes the ability to create firewall rules using the `iptables` command just like in any other case. Consider this very simple `.travis.yml` file:

```auto
---
script:
  - curl http://icanhazip.com

```

Test this somewhere in a repo and run it, it will work just fine:

```auto
$ curl http://icanhazip.com
104.196.57.92
The command "curl http://icanhazip.com" exited with 0.

```

In order to reproduce offline behavior, we just add firewall rules that block outbound access on port 80, and in some cases port 8080:

```auto
---
script:
  - sudo iptables -A OUTPUT -p tcp --dport 80 -j REJECT
  - curl http://icanhazip.com

```

On the same token, this will fail:

```auto
$ 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.

```

This is what makes Travis so amazing, the flexibility of it all. I hope this helps, if you need anything else please feel free to post back and I will gladly help you.

-Montana (Travis CI Staff)

---

<div class="post-metadata">

**Author:** ![OliBarrington](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/olibarrington/32/3745_2.png) [@OliBarrington](https://travis-ci.community/u/OliBarrington)\
**Post date:** [January 31, 2020, 10:33am UTC](https://travis-ci.community/t/block-network-access-of-a-test-process-on-travis/7070/3 "2020-01-31T10:33:27Z")

</div>

Thanks Montana!

---

<div class="post-metadata">

**Author:** ![Montana](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/montana/32/9566_2.png) [@Montana](https://travis-ci.community/u/Montana)\
**Post date:** [January 31, 2020, 10:36am UTC](https://travis-ci.community/t/block-network-access-of-a-test-process-on-travis/7070/4 "2020-01-31T10:36:52Z")

</div>

Of course, the Travis team is thrilled we can try and help each and every person that posts here!

-Montana
