FreeBSD and Linux Complementary Commands - Networking Edition
Apr 7, 2015 21:00
Linux looks like FreeBSD & FreeBSD looks like linux
The similarities between these two different systems can be misleading. For example, the Linux crowd will be confused about why they can’t ‘ip route’ to show the configured routes on a FreeBSD host. At the same time, folks who’ve used FreeBSD for a while will be confused as to why ‘ifconfig -a’ doesn’t work as expected on a Linux host. However, a lot of the same tools such as netstat, ifconfig, route etc. exist on both systems.
In this post, I’ll cover a few standard networking commands which may save you a couple of search engine cycles when hopping between the two systems.
Where my routes at?
Linux
# ip route
192.168.x.x/x dev eth0 proto kernel scope link src 192.168.x.x
169.254.0.0/16 dev eth0 scope link metric 1002
default via 192.168.x.x dev eth0
or
# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.x.x * 255.255.xxx.xxx U 0 0 0 eth0
link-local * 255.255.0.0 U 1002 0 0 eth0
default 192.168.x.x 0.0.0.0 UG 0 0 0 eth0
FreeBSD
# netstat -nr -f inet
Routing tables
Internet:
Destination Gateway Flags Refs Use Netif Expire
default 192.168.x.x UGS 0 4178 em0
127.0.0.1 link#4 UH 0 65 lo0
172.xx.xx.x/x link#2 U 0 0 em1
172.xx.xx.x link#2 UHS 0 0 lo0
172.xx.xx.x/x link#3 U 0 0 em2
172.xx.xx.x link#3 UHS 0 0 lo0
192.168.x.x/x link#1 U 0 8 em0
192.168.x.x link#1 UHS 0 0 lo0
The seasoned reader will notice that ‘netstat -nr’ may be used on either system. Also, the ‘route’ command exists on both systems but the FreeBSD implementation only manipulates the routing table.
Adding a static route
Linux
# ip route add x.x.x.z via <some-gateway-ip>
or
# route add -host x.x.x.z gw <some-gateway-ip>
FreeBSD
# route add -host x.x.x.x <some-gateway-ip>
Viewing IP addresses
Linux
# ip a show eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether de:ad:be:ef:12:24 brd ff:ff:ff:ff:ff:ff
inet 192.168.xx.xx/xx brd 192.168.xxx.xxx scope global eth0
inet6 fe80::5054:ff:fefa:bb90/64 scope link
valid_lft forever preferred_lft forever
FreeBSD
# ifconfig em0
em0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
options=209b<RXCSUM,TXCSUM,VLAN_MTU,VLAN_HWTAGGING,VLAN_HWCSUM,WOL_MAGIC>
ether DE:AD:BE:EF:12:34
inet 192.168.xxx.xx netmask 0xffffff00 broadcast 192.168.xxx.xxx
inet6 fe80::5054:ff:fe74:7627%em0 prefixlen 64 scopeid 0x1
nd6 options=29<PERFORMNUD,IFDISABLED,AUTO_LINKLOCAL>
media: Ethernet autoselect (1000baseT <full-duplex>)
status: active
Note that while ‘ifconfig’ may also be used in Linux, it’s usage is depracated in favor of ‘ip’ on most major Linux distros.
Is OpenSSH listening on port 22?
Linux
# netstat -tpln
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1754/sshd
tcp 0 0 :::22 :::* LISTEN 1754/sshd
FreeBSD
# sockstat -l
USER COMMAND PID FD PROTO LOCAL ADDRESS FOREIGN ADDRESS
root sshd 1468 3 tcp6 *:22 *:*
root sshd 1468 4 tcp4 *:22 *:*
Showing open connections
Linux
# netstat -ntp
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 192.168.x.x:22 xxx.xx.xx.xx:46079 ESTABLISHED 25578/sshd
FreeBSD
# sockstat -c -4
USER COMMAND PID FD PROTO LOCAL ADDRESS FOREIGN ADDRESS
test sshd 4483 3 tcp4 192.168.xxx.xx:22 xxx.xx.xx.xx:45299
root sshd 4480 3 tcp4 192.168.xxx.xx:22 xxx.xx.xx.xx:45299
Name resolution
Linux
# dig +short gmail.com @8.8.8.8 mx
30 alt3.gmail-smtp-in.l.google.com.
40 alt4.gmail-smtp-in.l.google.com.
20 alt2.gmail-smtp-in.l.google.com.
10 alt1.gmail-smtp-in.l.google.com.
5 gmail-smtp-in.l.google.com.
FreeBSD
# drill gmail.com @8.8.8.8 mx
...
;; ANSWER SECTION:
gmail.com. 3418 IN MX 10 alt1.gmail-smtp-in.l.google.com.
gmail.com. 3418 IN MX 40 alt4.gmail-smtp-in.l.google.com.
gmail.com. 3418 IN MX 30 alt3.gmail-smtp-in.l.google.com.
gmail.com. 3418 IN MX 5 gmail-smtp-in.l.google.com.
gmail.com. 3418 IN MX 20 alt2.gmail-smtp-in.l.google.com.
...