## Determine the current TCP/IP settings on a system ##

[Author](authors.html): Alex Nikiforov nikiforov.al@gmail.com FreeBSD

[Reviewer](technical_reviewers.html): Sean Swayze swayze@pcsage.biz FreeBSD

[Reviewer](technical_reviewers.html): Yannick Cadin yannick@diablotin.fr FreeBSD/OpenBSD

----



### Concept ###

Be able to determine a system's IP address(es),
subnet mask, default gateway, primary and secondary DNS servers and
hostname.


### Introduction ###

If you are a BSD user/administrator you must understand where and how you can get any information about a system such as its network settings. What interesting information about a network can we get from the system? We can obtain its IP address, default gateway, the DNS server, the MAC address of any network interface on the system and other relevant information related to networking.

TODO: show "hostname" tool

TODO: some BSDs have "route show" or "route get" ...

### Examples ###

Let's start from IP address and MAC address. We can get this kind of information from **ifconfig -a** command. For example

""wi0: flags=8802 &lt;BROADCAST,SIMPLEX,MULTICAST&gt; mtu 1500
        ether 00:05:3c:08:8f:7e
        media: IEEE 802.11 Wireless Ethernet autoselect \(none\)
        status: no carrier
        ssid "" channel 1
        stationname "FreeBSD WaveLAN/IEEE node"
        authmode OPEN privacy OFF txpowmax 100 bmiss 7
fxp0: flags=8843 &lt;UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST&gt; mtu 1500
        options=8<VLAN_MTU>
        inet 192.168.1.162 netmask 0xffffff00 broadcast 192.168.1.255
        ether 00:09:6b:13:42:9f
        media: Ethernet autoselect \(100baseTX &lt;full-duplex&gt;)
        status: active
lo0: flags=8049 &lt;UP,LOOPBACK,RUNNING,MULTICAST&gt; mtu 16384
        inet6 ::1 prefixlen 128 
        inet 127.0.0.1 netmask 0xff000000

As we can see the fxp0 interface has IP 192.168.1.162/24 (/24 means that the network mask is 255.255.255.0 - ffffff00), broadcast address 192.168.1.255, MAC address 00:09:6b:13:42:9f and 100baseTX full-duplex connection to the switch. Also the system has a wifi interface wi0 and also lo0 - the loopback interface.

Next step is to determine the DNS servers and default route.
""#netstat -rn
Routing tables

""Internet:
Destination        Gateway            Flags    Refs      Use  Netif Expire
default            192.168.1.1        UGS         0      919   fxp0
127.0.0.1          127.0.0.1          UH          0        0    lo0
192.168.1          link#2             UC          0        0   fxp0
192.168.1.1        00:13:46:56:cf:15  UHLW        2        0   fxp0   1178

That means that the default gateway IP is 192.168.1.1.

""> cat /etc/resolv.conf
""nameserver 192.168.1.1
""nameserver 10.2.2.1
""> 

**resolv.conf** has IP addresses of DNS server. For this example the system will first try to resolve DNS name with 192.168.1.1, secondly with 10.2.2.1(The system will really try to resolve DNS name with hosts file, if the name is not in the hosts file system (hosts.conf) try to resolve it with a DNS server). You can edit **resolv.conf** on the fly.

Some times system have some static route for hosts on the network. For save this you can use **rc.conf** file. And you can update routes on the fly. For example, if you need change default route. Let's try changing the default route:

""# route flush
""default              192.168.1.1          done
""# route add 0.0.0.0 192.168.1.1
""add net 0.0.0.0: gateway 192.168.1.1
""# 

Route flush means that you want flush all routes on your system, instead of this you can use the **route delete** command (look at the manual for your system). **route add 0.0.0.0** means that you want add route for 0.0.0.0 network - all networks(also you can do it like that **route add default 192.168.1.1**) and 192.168.1.1 it's IP for your default router.

### Practice Exercises ###

1. Try to access your DNS-servers.
2. List the IP addresses of each interface, the default router, list the DNS servers.
3. Log into your system and verify that the DNS servers correspond to that of your ISP or your own.
4. Log into your system and verify that you have a valid, IP address and default gateway.


### More information ###

ifconfig(8), netstat(1), resolv.conf(5), route(8), hostname(1)
