[GH-ISSUE #1476] What is the syntax for hosts-file in profiles ? #988

Closed
opened 2026-05-05 07:16:14 -06:00 by gitea-mirror · 4 comments
Owner

Originally created by @ghost on GitHub (Aug 18, 2017).
Original GitHub issue: https://github.com/netblue30/firejail/issues/1476

hosts-file ~/.tmp/hosts doesn't work.

Originally created by @ghost on GitHub (Aug 18, 2017). Original GitHub issue: https://github.com/netblue30/firejail/issues/1476 hosts-file ~/.tmp/hosts doesn't work.
gitea-mirror 2026-05-05 07:16:14 -06:00
Author
Owner

@netblue30 commented on GitHub (Aug 19, 2017):

It has the default syntax for /etc/hosts file:

$ cat ~/.tmp/hosts
127.0.0.1	localhost
127.0.1.1	debian

127.0.0.1	google.com

$ firejail --noprofile --hosts-file=~/.tmp/hosts
Parent pid 19549, child pid 19550
Child process initialized in 19.55 ms

$ cat /etc/hosts
127.0.0.1	localhost
127.0.1.1	debian

127.0.0.1	google.com

$ ping google.com
PING google.com (127.0.0.1) 56(84) bytes of data.
64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.041 ms
64 bytes from localhost (127.0.0.1): icmp_seq=2 ttl=64 time=0.053 ms
^C
--- google.com ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1000ms
rtt min/avg/max/mdev = 0.041/0.047/0.053/0.006 ms
$ 
<!-- gh-comment-id:323519655 --> @netblue30 commented on GitHub (Aug 19, 2017): It has the default syntax for /etc/hosts file: ````` $ cat ~/.tmp/hosts 127.0.0.1 localhost 127.0.1.1 debian 127.0.0.1 google.com $ firejail --noprofile --hosts-file=~/.tmp/hosts Parent pid 19549, child pid 19550 Child process initialized in 19.55 ms $ cat /etc/hosts 127.0.0.1 localhost 127.0.1.1 debian 127.0.0.1 google.com $ ping google.com PING google.com (127.0.0.1) 56(84) bytes of data. 64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.041 ms 64 bytes from localhost (127.0.0.1): icmp_seq=2 ttl=64 time=0.053 ms ^C --- google.com ping statistics --- 2 packets transmitted, 2 received, 0% packet loss, time 1000ms rtt min/avg/max/mdev = 0.041/0.047/0.053/0.006 ms $ `````
Author
Owner

@ghost commented on GitHub (Aug 19, 2017):

I'm using this, I don't know what the default syntax for a hosts file is but if it works in /etc/hosts I thought it can also work in a firejail profile. https://github.com/StevenBlack/hosts

<!-- gh-comment-id:323521801 --> @ghost commented on GitHub (Aug 19, 2017): I'm using this, I don't know what the default syntax for a hosts file is but if it works in /etc/hosts I thought it can also work in a firejail profile. https://github.com/StevenBlack/hosts
Author
Owner

@netblue30 commented on GitHub (Aug 19, 2017):

I copied https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts in a file in my home directory and run it:

$ firejail --noprofile --hosts-file=~/myhosts
Parent pid 10649, child pid 10650
Child process initialized in 22.43 ms
[netblue@debian test-hosts]$ less /etc/hosts

<<<<< I can see the file mounted in /etc/hosts

$ ping yesads.com   <<<<< this is redirected to 127.0.0.1 (my local host)
PING yesads.com (127.0.0.1) 56(84) bytes of data.
64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.040 ms
64 bytes from localhost (127.0.0.1): icmp_seq=2 ttl=64 time=0.051 ms
64 bytes from localhost (127.0.0.1): icmp_seq=3 ttl=64 time=0.065 ms

You need to grab the resulting hosts file created by the https://github.com/StevenBlack/hosts after you clone their git repository. I'm not sure how they generate the file.

<!-- gh-comment-id:323522973 --> @netblue30 commented on GitHub (Aug 19, 2017): I copied https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts in a file in my home directory and run it: ````` $ firejail --noprofile --hosts-file=~/myhosts Parent pid 10649, child pid 10650 Child process initialized in 22.43 ms [netblue@debian test-hosts]$ less /etc/hosts <<<<< I can see the file mounted in /etc/hosts $ ping yesads.com <<<<< this is redirected to 127.0.0.1 (my local host) PING yesads.com (127.0.0.1) 56(84) bytes of data. 64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.040 ms 64 bytes from localhost (127.0.0.1): icmp_seq=2 ttl=64 time=0.051 ms 64 bytes from localhost (127.0.0.1): icmp_seq=3 ttl=64 time=0.065 ms ````` You need to grab the resulting hosts file created by the https://github.com/StevenBlack/hosts after you clone their git repository. I'm not sure how they generate the file.
Author
Owner

@ghost commented on GitHub (Aug 19, 2017):

It works now, I have no idea why it didn't work before as I did exactly the same thing.Thanks. I've also realized the other issue of mine doesn't make sense at the momment, please take a look after I rephrase it.
https://github.com/netblue30/firejail/issues/1478

<!-- gh-comment-id:323532747 --> @ghost commented on GitHub (Aug 19, 2017): It works now, I have no idea why it didn't work before as I did exactly the same thing.Thanks. I've also realized the other issue of mine doesn't make sense at the momment, please take a look after I rephrase it. https://github.com/netblue30/firejail/issues/1478
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: github-starred/firejail#988
No description provided.