2

I am making a program that scrapes information from some web services. I want to test how my program reacts when it can't reach the web service, like if the web service is down or if the local computer has no internet access. Disconnecting my whole computer from the network every time I want to run a test is far too much work.

Is there a simple way to run a program under Linux with no network access?

A command like this would be awesome:

$ no_networking "ruby my_program.rb"
Hubro
  • 1,095
  • 1
  • 11
  • 19

1 Answers1

1

You have several options like adding the host you want to connect to into the /etc/hosts file:

vi /etc/hosts, add: 10.0.0.1 host.where.i.want.to.connect.to

make sure that 10.0.0.1 is an IP address which does not exist in your network. Using this method you are overriding the resolving of the host you have configured in your my_program.rb application. If you want to 'allow' normal access again, you can simply comment the line in the /etc/hosts file by prefixing the line with a # character.

Another option is to add a firewall rule which blocks or rejects traffic to the host you are connecting to.

Lambert
  • 12,680