I'm building a tool to manage DNS in macOS.
I know how to set dns server in terminal.
networksetup -setdnsservers Wi-Fi 1.1.1.1
but I don't to know how to unset it, or set it to the default value
networksetup -setdnsservers Wi-Fi
seems not working.
Anyone help ?
Give a try to:
networksetup -setdnsservers Wi-Fi empty
Then check with:
scutil --dns
From man networksetup:
-setdnsservers networkservice dns1 [dns2] [...]
...
If you want to clear all DNS entries for the specified network service,
type "empty" in place of the DNS server names.
Related
in Windows i'm using as below.
netsh wlan connect ssid=YOUR-WIFI-SSID name=PROFILE-NAME
Need similar for the mac os.
I think it will depend on whether you have saved the WiFi password in your keychain but the basic command is networksetup as follows:
networksetup -setairportnetwork en0 YOUR_NETWORD_SSID
For more information, try:
man networksetup
I made some research and can't find a solution, I'm starting to think this is not possible.
I'm running arp -a in my terminal and I'd like to get the hostnames of the LAN devices.
host x.x.x.x returns:
Host x.x.x.x.in-addr.arpa. not found: 3(NXDOMAIN)
nslookup x.x.x.x returns:
** server can't find x.x.x.x.in-addr.arpa: NXDOMAIN
Is there a way to do this?
arp -a does the reverse DNS by default on linux machines. On macOS I guess you will have to run nslookup on each entry returned by arp -a table.
I found a way thanks to #gordon-davisson who set me on the right path.
First I get the gateway IP with: route get default | grep gateway
Then for every LAN device I run: host LAN_IP Gateway_IP
This returns:
Using domain server:
Name: 192.168.x.x
Address: 192.168.x.x#x
Aliases:
x.x.168.192.in-addr.arpa domain name pointer LAN-host-name.
I parse the response to get the name displayed at the end.
Side note: it still doesn't display the LAN host-names with arp -a after that.
I am using macOS 10.12 and I want to do ip:port mapping
ex. 127.0.0.1:32769 to 10.0.0.1
then I can add 10.0.0.1 somedomain.com to my /etc/hosts
I did some search, and got solutions to this question on this post:
https://serverfault.com/questions/102416/iptables-equivalent-for-mac-os-x/673551#673551
but the command in this post works for only the newest one.
every time I use this command the system replies me:
$ sudo ifconfig lo0 10.0.0.2 alias
$ echo "rdr pass on lo0 inet proto tcp from any to 10.0.0.2 port 80 -> 127.0.0.1 port 32771" | sudo pfctl -ef -
pfctl: Use of -f option, could result in flushing of rules
present in the main ruleset added by the system at startup.
See /etc/pf.conf for further details.
No ALTQ support in kernel
ALTQ related functions disabled
pfctl: pf already enabled
how can I prevent flushing rules?
or is there any ways to get this work easier?
Thanks a lot
Hi i'm look for why my ping command doesn't work when it had a dash in the name for example
Ping HIL-BO
Will get:
Ping request could not find host HIL-BO. Please check the name and try again.
But when i type
Net view
[backslash][backslash] HIL-BO is in the outputted text
why wont this work please help
/Screenshot/
You can not ping to a windows network name except it the same as the DNS entry for your computers IP-address. I'm not a windows user, but the following should work. Try
ipconfig /a
This should show you a list that contains your IP-address. I expect that, you have no DNS entry so you must use the xxx.xxx.xxx.xxx IP-address that will be shown by ipconfig.
ping xxx.xxx.xxx.xxx
(replace the xxx.xxx.xxx.xxx by the displayed address). If you ping the same machine try:
ping localhost
The ping command can only work if the ping service on the target machine is running and the firewall is opend for ICMPv4 protocol and ports.
I set up a proxy on Mac via System Preferences -> Network -> Advanced -> Proxies.
Is that possible to do the same programatically via bash shell?
You can put this in your .profile or .bash_profile or run manually on a command line:
export http_proxy=http://proxy.server.com:#aproxy:portnumber
export https_proxy=https://proxy.server.com:#aproxy:portnumber
It's also common to not use the proxy for the local connections
export no_proxy=localhost,127.0.0.0/8,*.local
Yes, using the networksetup command. There are separate options for setting different types of proxies (e.g. -setwebproxy, -setsocksfirewallproxy, etc), and you need to know the name of the primary network "service" (e.g. Ethernet, Airport... basically, the names listed in the sidebar of the Network preferences pane). Here's an example:
sudo networksetup -setwebproxy "Ethernet" myproxy.example.com 8000
If you need to figure out the service name, use networksetup -listnetworkserviceorder or networksetup -listallnetworkservices, then parse the list to get the name of the service you want.
I use this script to proxy through my ssh server (not a web proxy).
#!/bin/bash
disable_proxy(){
sudo networksetup -setsocksfirewallproxystate Wi-Fi off
sudo networksetup -setsocksfirewallproxystate Ethernet off
echo "SOCKS proxy disabled."
}
trap disable_proxy INT
sudo networksetup -setsocksfirewallproxy Wi-Fi 127.0.0.1 9999
sudo networksetup -setsocksfirewallproxy Ethernet 127.0.0.1 9999
sudo networksetup -setsocksfirewallproxystate Wi-Fi on
sudo networksetup -setsocksfirewallproxystate Ethernet on
echo "SOCKS proxy enabled."
echo "Tunneling..."
ssh -ND 9999 000.000.000.000 -p 00000
Change 000.000.000.000 to your own server's IP and 00000 to your own port and you should be able to reuse it with your own ssh server. You can save this script in your home directory named say proxy.
Start it with ./proxy (type your password), use CTRL+C to stop tunnelling.
Start it again and stop with CTRL+C if you forgot to stop tunnelling and next day you are wondering why your internet connection is down.
If you get a broken pipe, just start ./proxy again.