2

It is possible to use wildcard in /etc/hosts file?

For example, im developng the application that will have user-defined subdomains, like "user1.foo.bar", "user2.foo.bar".

Im looking for something like this:

127.0.0.1 foo.bar
127.0.0.1 *.foo.bar

How can i make it work ?

2 Answers 2

5

No. You need a full blown DNS server to do this.

1
  • Second that, you can't. Aug 7, 2009 at 19:47
2

No you can't as has been stated, but...

If the hostnames follow what you are saying though, you could do this with the Bash shell to save you some typing:

for i in user{1..10}; do 
    sudo bash -c "echo 127.0.0.1 ${i}.foo.bar >> /etc/hosts"
done

Or, say you have them all in a text file one host per line:

while read host; do
    sudo bash -c "echo 127.0.0.1 $host >> /etc/hosts"
done < fileName
1
  • of course, i can use static names, but the question not about it. thanks anyway. Aug 7, 2009 at 20:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .