What's the proper way to determine the computer's gateway when going from DHCP to a static IP. Operating system is Mythbunutu with Ububtu desktop installed.
I had previously been editing /etc/network/interfaces, but eventually the computer would stop being able to connect to the Internet (although computers behind the access point could still connect to it).
Now I'm using gnome-network-admin assuming the GUI knows what's going on behind the scenes better than I do.
23 Answers
To get your gateway's IP address, use the route command with the -n flag to translate hostnames into IP addresses (or rather, disable DNS lookups on the IP address).
$ route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
10.10.10.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
0.0.0.0 10.10.10.1 0.0.0.0 UG 100 0 0 eth0The default gateway is the one where the destination is 0.0.0.0, in this case, 10.10.10.1.
Though I'm wondering, why are you manually assigning a static IP? Does your access device (router, wifi, whatever) not allow DHCP reservations? Most devices do these days. You just need to provide the MAC address, and many will already know the MAC by hostname. If your's doesn't you can get the MAC from ip, the "link/ether" address:
$ ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo inet6 ::1/128 scope host valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN qlen 1000 link/ether 00:50:56:10.10:21 brd ff:ff:ff:ff:ff:ff inet 10.10.10.121/24 brd 10.10.10.255 scope global eth0 inet6 fe80::250:56ff:fe10.1021/64 scope link valid_lft forever preferred_lft foreveror ifconfig, the "HWaddr" address:
$ ifconfig
eth0 Link encap:Ethernet HWaddr 00:50:56:10.10:21 inet addr:10.10.10.121 Bcast:10.10.10.255 Mask:255.255.255.0 inet6 addr: fe80::250:56ff:fe10.1021/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:107139 errors:0 dropped:0 overruns:0 frame:0 TX packets:12345 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:29375815 (29.3 MB) TX bytes:1447714 (1.4 MB) Interrupt:18 Base address:0x2000 2 /etc/network/interfaces is the right thing to use, but the GUI tools are fine as well.
Are you simply statically configuring the same IP that DHCP gave you? If you do that, the DHCP server will eventually lease the same IP out to another computer/device and you'll have an IP conflict. If you give your system an IP via any of those static methods, you need to give it an IP nothing else will use. Either outside the range of DHCP, or one that DHCP knows belongs only to your MAC address. If you configure a static assignment on the DHCP server for your MAC address, you shouldn't have to worry about any of this...
jtimberman and freiheit provided good answers. Let me add one thing: it is not clear if you are the network administrator or not. If you are not, assigning IP addresses statically when the network is supposed to use DHCP is really playing the Sorcerer's Apprentice. You can create a lot of problems (assigning an existing IP address, for instance).
2