brent Not sure where you found this, but most of these don't actually perform a DNS cache flush. Let's go through them:
Debian/Ubuntu: sudo service network-manager restart
Linux with systemd: sudo systemctl restart network.service
Fedora Linux: sudo systemctl restart NetworkManager.service
Arch Linux/Manjaro with Network Manager: sudo systemctl restart NetworkManager.service
RHEL/Centos: sudo /etc/init.d/network restart
These commands restart the networking stack. This does usually deconfigure the upstream DNS server, which may lead to a flushed cache: if you don't have a caching resolver on your local system it will do nothing. When you do it depends entirely on what resolver you are using.
Linux Mint: sudo /etc/init.d/dns-clean start
This does flush the cache when there is a caching resolver (but is ancient).
Arch Linux/Manjaro with Wicd: sudo systemctl restart wicd.service
This only restarts the wireless networking, which leads to a loss of networking connection, which in turn may lead to a flushed DNS cache (see above). I don't think theres a more indirect way of possibly doing things.
FreeBSD: sudo service nscd restart
This is the only command in the list which (to my knowledge) is both correct and current.
Now for how you actually determine what should be done:
Look at the IP address of your current resolver in /etc/resolv.conf
. Depending on this value there are things you can do:
127.0.0.53
: systemd-resolved
: sudo resolvectl flush-caches
127.0.0.x
or ::1
: other local resolver. Find it and restart it.
- LAN IP (usually
192.168.x.y
, 10.x.y.z
, or starting with fe80::
): Probably your router. Try turning it off and on again (but notify other users first!).
- Internet IP: it is probably not possible to flush the caches. Notable exceptions: Google DNS and CloudFlare DNS.
If flushing the caches is not possible or doesn't work it's always worth it to try configuring a different resolver though UI. Well-known options are: Google DNS, CloudFlare DNS and Quad9.