check information
[!NOTE|label:references:]
$ scutil --nwi
Network information
IPv4 network interface information
en8 : flags : 0x5 (IPv4,DNS)
address : 10.1.1.1
reach : 0x00000002 (Reachable)
en0 : flags : 0x5 (IPv4,DNS)
address : 192.168.6.55
reach : 0x00000002 (Reachable)
REACH : flags 0x00000002 (Reachable)
IPv6 network interface information
No IPv6 states found
REACH : flags 0x00000000 (Not Reachable)
Network interfaces: en8 en0
get interface
# default route
$ ip route get $(dig +short github.com | head -1) | sed -rn 's|.*dev\s+(\S+)\s+src.*$|\1|p')
# or
$ ip route get $(nslookup "${githubIp}" | grep Server | awk -F' ' '{print $NF}') | sed -rn 's|.*dev\s+(\S+)\s+src.*$|\1|p'
en8
# all active interface
$ netstat -nr | grep -E 'UG|UGSc' | grep -E '^0.0.0|default' | grep -E '[0-9.]{7,15}' | awk -F' ' '{print $NF}'
en0
en8
list all interfaces
$ /sbin/ifconfig | grep --color=none flags=8863 | grep -v bridge en5: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500 en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500 llw0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500 en8: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500 # or $ scutil --nwi | awk -F': ' '/Network interfaces/ {print $2;exit;}' en8 en0
get ip address
$ ipAddr=$(/usr/local/bin/ip a s "${interface}" | sed -rn 's|\W*inet[^6]\W*([0-9\.]{7,15}).*$|\1|p')
# or via `/sbin/ifconfig`
$ ipAddr=$(/sbin/ifconfig "${interface}" | sed -rn 's|^\s+inet\s+([0-9\.]+))
get mac address
$ ip link show ${interface} | sed -rn 's|.*ether ([0-9a-fA-F:]{17}).*$|\1|p' | sed 's|:||g' | tr [a-z] [A-Z]
get interface information
#!/bin/bash
while read -r line; do
sname=$(echo "$line" | awk -F "(, )|(: )|[)]" '{print $2}')
sdev=$(echo "$line" | awk -F "(, )|(: )|[)]" '{print $4}')
# echo "Current service: $sname, $sdev, $currentservice"
if [ -n "$sdev" ]; then
ifout="$(/sbin/ifconfig "$sdev" 2>/dev/null)"
echo "$ifout" | grep 'status: active' > /dev/null 2>&1
rc="$?"
if [ "$rc" -eq 0 ]; then
currentservice="$sname"
currentdevice="$sdev"
currentip=$(echo "${ifout}" | sed -rn 's|^\s+inet\s+([0-9\.]+).*$|\1|p')
currentmac=$(echo "$ifout" | awk '/ether/{print $2}')
# may have multiple active devices, so echo it here
echo "$currentservice, $currentdevice, $currentmac, ${currentip}"
fi
fi
done <<< "$(networksetup -listnetworkserviceorder | grep --color=none 'Hardware Port')"
route
[!NOTE|label:references:]
- * imarslo : route
- * imarslo : ubuntu 17.10 bootup settings
- Adding a Static Route to macOS
- How to get routing table in terminal [duplicate]
- can we change default gateway and interface in mac through commandline
- Viewing the routing table from the command-line interface
- * Chapter 4 Administering TCP/IP (Task)
- route flags
FLAG | DESCRIPTION |
---|---|
U | Up—Route is valid |
G | Gateway—Route is to a gateway router |
H | Host name—Route is to a host rather than to a network |
R | Reject—Set by ARP when an entry expires |
D | Dynamic—Route added by a route redirect or RIP |
M | Modified—Route modified by a route redirect |
C | Cloning—A new route is cloned from this entry when it is used |
L | Link—Link-level information, such as the Ethernet MAC address, is present |
S | Static—Route added with the route command |
check route
show all
# linux-like route -n $ netstat -nr # or $ netstat -nr -f inet # via `ip route` $ ip route show
show particular ip
$ route get <ip.address> route to: ec2-1-1-1-1.compute-1.amazonaws.com destination: ec2-1-1-1-1.compute-1.amazonaws.com gateway: 192.168.0.1 interface: en0 flags: <UP,GATEWAY,HOST,DONE,STATIC> recvpipe sendpipe ssthresh rtt,msec rttvar hopcount mtu expire 0 0 0 77 11 0 1500 0 # or via `ip route` $ ip route get 1.1.1.1 1.1.1.1 via 192.168.0.1 dev en0 src 192.168.6.55
display network interface status
$ netstat -i
-
$ /usr/sbin/in.routed /var/logfilename
add a static route item
$ sudo route -nv add -host <ip.address> <gateway>
# or
$ sudo route add -host <ip.address> -iface en1
delete a static route
$ sudo route delete <ip.address> <gateway>
vpn
[!NOTE|label:references:]