1001Ferramentas
🗂️Dev

/etc/hosts a partir de CSV

Monta entradas /etc/hosts a partir de CSV (ip,hostname por linha).

hosts file

From a spreadsheet of IPs to a hosts file

Someone handed you a list of machines as CSV, IP in the first column and hostname in the second, and you need it in hosts file format, where the fields are separated by a space or a tab. Retyping forty lines by hand is exactly where the typo comes from that costs you an hour of debugging later. Paste the CSV and each line becomes an entry with the IP, a tab and the hostname.

The conversion runs line by line and drops anything missing either field, so blank lines and lines without a comma disappear. What it does not do is recognize a header row: if your CSV starts with ip,hostname, that line becomes a literal entry containing the words ip and hostname. Delete it first. Extra columns past the second comma are ignored, and the IP is never validated, so 999.1.2.3 sails right through.

Double-check the line breaks after pasting into your editor, and remember the file lives at /etc/hosts on Linux and macOS and at C:\Windows\System32\drivers\etc\hosts on Windows, needing administrator rights either way. A hosts file accepts no wildcards and no ports: *.dev will not work and the name has to match exactly. On macOS, flush the cache afterwards with sudo dscacheutil -flushcache and sudo killall -HUP mDNSResponder. The conversion runs in your browser.

Frequently asked questions

Can I keep comment lines in the CSV?
A line without a comma is dropped, so comments vanish instead of becoming broken entries. If you want them, add the # lines after pasting everything into the hosts file.
How do I point several names at the same IP?
Repeat the IP on one CSV line per hostname. The hosts format also allows several aliases on a single line, but you would merge those by hand afterwards.
Does it work with IPv6 addresses?
Yes. The text is copied through as typed, and IPv6 uses colons rather than commas, so a line like ::1,localhost converts normally.

Related Tools