Difference between revisions of "Networking notes"

From Noah.org
Jump to navigationJump to search
m
m
Line 1: Line 1:
 
[[Category: Engineering]]
 
[[Category: Engineering]]
 
[[Category: Networking]]
 
[[Category: Networking]]
This describes permanent Linux network interface settings. That is, settings so that they will be restored after a reboot.
+
 
 +
== How to configure a persistent network settings ==
 +
 
 +
This describes persistent Linux network interface settings. That is, settings that will be restored after a reboot.
  
 
After you make changes you will need to restart the networking subsystem to make the changes active:
 
After you make changes you will need to restart the networking subsystem to make the changes active:
 
 
<pre>
 
<pre>
 
/etc/init.d/networking restart
 
/etc/init.d/networking restart
 
</pre>
 
</pre>
  
== DHCP ==
+
=== Debian/Ubuntu ===
 
 
<pre>
 
iface eth0 inet dhcp
 
</pre>
 
 
 
== How to permanently set static IP in Ubuntu ==
 
  
 
Edit the file:
 
Edit the file:
Line 23: Line 19:
 
Edit the section for your primary network interface. Example for setting up 192.168.1.66:
 
Edit the section for your primary network interface. Example for setting up 192.168.1.66:
  
 +
Static IP address:
 
<pre>
 
<pre>
 
auto eth0
 
auto eth0
Line 29: Line 26:
 
     netmask 255.255.255.0
 
     netmask 255.255.255.0
 
     gateway 192.168.1.1
 
     gateway 192.168.1.1
 +
</pre>
 +
DHCP assigned IP address:
 +
<pre>
 +
iface eth0 inet dhcp
 
</pre>
 
</pre>
  
Line 37: Line 38:
 
</pre>
 
</pre>
  
== How to set static IP in RedHat ==
+
=== RedHat ===
  
 
All network config files are in this directory:
 
All network config files are in this directory:
Line 69: Line 70:
 
You don't need to worry about the broadcast address (or Bcast). By default, it is set to the interface address bitwise OR'ed with the inverse of the netmask.
 
You don't need to worry about the broadcast address (or Bcast). By default, it is set to the interface address bitwise OR'ed with the inverse of the netmask.
  
== howto change the interface name for a new network device using udev ==
+
== how to change the interface name for a new network device using udev ==
  
 
Ubuntu uses udev to keep device names consistent between each boot or device hot-swap. It keeps track of the MAC address of the device and matches any previously seen MAC address with a previously assigned interface name. If it has never seen the new MAC address before then the device is assigned a new interface name and that MAC-to-ifname mapping is recorded for later.
 
Ubuntu uses udev to keep device names consistent between each boot or device hot-swap. It keeps track of the MAC address of the device and matches any previously seen MAC address with a previously assigned interface name. If it has never seen the new MAC address before then the device is assigned a new interface name and that MAC-to-ifname mapping is recorded for later.
Line 98: Line 99:
 
On Linux you can use `netstat -rn` or `route` or `ip route`.
 
On Linux you can use `netstat -rn` or `route` or `ip route`.
  
I always forget this when I got on a BSD machine. I got some kind of block against this:
+
I always forget this when I work on a BSD machine. I've got some kind of mental block against this:
  
 
<pre>
 
<pre>

Revision as of 14:07, 8 February 2011


How to configure a persistent network settings

This describes persistent Linux network interface settings. That is, settings that will be restored after a reboot.

After you make changes you will need to restart the networking subsystem to make the changes active:

/etc/init.d/networking restart

Debian/Ubuntu

Edit the file:

 /etc/network/interfaces 

Edit the section for your primary network interface. Example for setting up 192.168.1.66:

Static IP address:

auto eth0
iface eth0 inet static
    address 192.168.1.66
    netmask 255.255.255.0
    gateway 192.168.1.1

DHCP assigned IP address:

iface eth0 inet dhcp

Restart the network layer:

/etc/init.d/networking restart

RedHat

All network config files are in this directory:

 /etc/sysconfig/network-scripts

Each interface will have its own file named after the infterface:

 ifcfg-eth0
 ifcfg-eth1
 ifcfg-lo

The contents of a minimal ifcfg-eth0 file looks like this (GATEWAY may not be needed if you are just setting up a LAN between a few machines):

DEVICE=eth0
ONBOOT=yes
BOOTPROTO=static
IPADDR=10.1.0.1
NETMASK=255.255.255.0
GATEWAY=10.0.0.1

You need to restart the network system to have the new settings take effect:

 # service network restart

Broadcast

You don't need to worry about the broadcast address (or Bcast). By default, it is set to the interface address bitwise OR'ed with the inverse of the netmask.

how to change the interface name for a new network device using udev

Ubuntu uses udev to keep device names consistent between each boot or device hot-swap. It keeps track of the MAC address of the device and matches any previously seen MAC address with a previously assigned interface name. If it has never seen the new MAC address before then the device is assigned a new interface name and that MAC-to-ifname mapping is recorded for later.

Sometimes you replace a network card or swap out the entire motherboard; you never intend to plug in the old device again and you want the new device to take on the old interface name.

Ubuntu keeps track of the mappings in this file: /etc/udev/rules.d/70-persistent-net.rules You may edit this file, but be sure to obey the comment in the file, "# You can modify it, as long as you keep each rule on a single line."

# PCI device 0x14e4:0x164c (bnx2)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:22:19:b7:a5:42", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"

Set the NAME parameter; write the file; then run '...TODO...'.

routing the route

add a route

This can also be done with the ip2 command:

route add default gw 192.168.1.1

display routing table

On Linux you can use `netstat -rn` or `route` or `ip route`.

I always forget this when I work on a BSD machine. I've got some kind of mental block against this:

netstat -rn

LOWER_UP

The `ip link show` command will display flags associated with each interface. One that used to bug me was 'LOWER_UP'. What the hell? It wasn't documented anywhere in the iproute2 tools. Eventually I heard from word of mouth that it was the physical layer link flag; meaning, if LOWER_UP was set then your Ethernet cable was plugged in and connected to a network. I finally went through the source and found the definition in <linux/if.h>, see IFF_LOWER_UP.