Connection timed out when running commands in macOS
Selasa, 23 April 2024, 2:35 pm0
![F52FE925-A5B4-4A8D-AE3F-3ADC6F4663BF.jpeg](https://azwan082.my/wp-content/uploads/2024/04/F52FE925-A5B4-4A8D-AE3F-3ADC6F4663BF.jpeg)
I stored some cron job on this Mac which require a connection to remote website. After left the computer running for several days, suddenly the cron job failed with ‘connection timed out’ error.
Previously I solved this issue by restarting the computer, but that just temporary, after a few days the issue occur again & it’s not practical if I’m away from home.
![176D19AC-D19A-4645-B388-3E71B42E20DB.jpeg](https://azwan082.my/wp-content/uploads/2024/04/176D19AC-D19A-4645-B388-3E71B42E20DB.jpeg)
Notice that the first attempt failed with error ‘network is unreachable’ & www.google.com.my
is resolved to an IPv6 address. But the second attempt, it succeed when using IPv4 address.
So I lookup on the ‘net on how to force macOS to use IPv4 address when trying to connect to remote server, and found this forum thread ⁽¹⁾.
![95C79C78-891A-4495-9C74-EF2DE1835950.jpeg](https://azwan082.my/wp-content/uploads/2024/04/95C79C78-891A-4495-9C74-EF2DE1835950.jpeg)
Open System Preferences > Network > select Wi-Fi > Advanced > TCP/IP tab > Configure IPv6, choose Link-local only.
What this does is when we’re running command to connect to remote website (e.g wget
, youtube-dl
or #NodeJS fetch()
), it will use IPv4 address instead of IPv6.
Done . #webdev
⁽¹⁾ https://discussions.apple.com/thread/251035348
Simplest JS promise tutorial using await / async
24 April 2024
Penutup liburan raya, ngeteh di atas bukit
22 April 2024