The gMan nixWiki

Because the mind is made of Teflon...

User Tools

Site Tools


general_network

This is an old revision of the document!


Network Commands

see IP info

Pick one, they basically do the same thing:

 ifconfig -a        # Debian net-tools pkg
 ls /sys/class/net  # ls interface names
 ip a
 ip a show
 ip a show eth0

manual up/down

Manually bringing your network up and down (nixCraft has a good explanation):

  • Assuming eth0 (change for whichever interface you want to manipulate).

Generic Method:

ifdown eth0   # Turn off eth0
ifup eth0     # Turn on eth0

Use a specific configuration file:

ifdown wlan0  # bring interface down
ifup --interfaces /path/to/file/interface_config_file wlan0

Debian Method (as root):

/etc/init.d/networking restart  # Restarts network interfaces, or stop/start... 
/etc/init.d/networking stop     # Stops network interfaces
/etc/init.d/networking start    # Starts network interfaces

systemctl restart networking    # For those with lovely systemd
systemctl status network        # See status of network systemd

ifupdown vs. ifconfig

Debian, overview:

  • ifup and ifdown control interfaces that are listed in /etc/network/interfaces.
  • ifconfig directly controls network interfaces (much like the newer ip command)

The ifupdown package: high-level network configuration

  • The ifup and ifdown commands may be used to configure or deconfigure network interfaces based on interface definitions in the file /etc/network/interfaces.
  • Example: bring up the network with ifup eth0 based on eth0 configuration in /etc/network/interfaces.
  • ifupdown will wrap ifconfig with the network configuration files (i.e., ifdown or ifup will execute ifconfig down or ifconfig up inside it). That means:
    • ifup eth0 will fetch the interface config file and bring up the interface with the correct IP address, mask, routes etc.
    • ifconfig eth0 up would just start the interface with no IP, etc. (important for sniffing in monitor mode because you don't want an IP address, etc.; you want an open broadcase).

The ifconfig command: a low-level network command (and deprecated, sadly)

  • An ifconfig up eth0 activates eth0 but does not setup IP addresses, etc.
  • An ifup eth0 sets up IP addresses and other options based on the interface's configuration in /etc/network/interfaces.

ip command

Usage of the ip command:

  • If your distro did not install ifconfig, you can install it in Debian with apt install net-tools.
  • Or you can use the horridly ugly syntax for ip (complex and hard-to-understand help can be found here or an easier-to-understand explanation here).
  • From the following example you will need to replace the IP and the interface with your own.

[1] Assign an IP address to a specific interface:

ip addr add 192.168.0.100/24 dev eth0

[2] Bring up the interface link (do NOT skip this step or you will get a “Network is unreachable” error!):

ip link set eth0 up

[3] Bring up the interface link:

ip route add default via 192.168.0.1

[1-3] All in one place… looks like this:

ip addr add 192.168.0.100/24 dev eth0
ip link set eth0 up
ip route add default via 192.168.0.1

Note on Persistence: This will only set up your network for your current work session. You'll lose it on reboot.

  • ip (like the old net-tools ifconfig stuff) interacts with /etc/network/interfaces, so put all your network configuration information there and just up/down your network with these commands:
/etc/init.d/networking restart  # Restarts network interfaces, or stop/start... 
/etc/init.d/networking stop     # Stops network interfaces
/etc/init.d/networking start    # Starts network interfaces

Network Management

Three Options

There are 3 services that might be managing your network (in order to avoid configuration conflicts related to networks, only one networking service should be enabled at one time)…

  1. ifupdown
  2. systemd-networkd
  3. Network Manager

ifupdown

If you are used to manage your networks using the “interfaces” file, you might want to keep doing that, otherwise it is recommended to switch to the Network Manager.

If you cannot do an ifconfig the install the net-tools package

This is the traditional (old school, deprecated) way to manager network interfaces. it is done through a configuration files located:

/etc/network/interfaces

If your distro installed Network Manager and you want to use ifupdown, do the following… 1. Include ifupdown as the first option of plugins in your [main] section of the NetworkManager.conf file (see below). 2. You can also change managed=false to managed=true in the [ifupdown] section of the NetworkManager.conf file (see below). 3. Manually configure your interfaces in /etc/network/interfaces.

  • This should be all you need to do (i.e., you probably don't even need to worry about steps 1 & 2).
  • The moment you configure an interface in /etc/network/interfaces, network-manager ignores that interface automatically. No need to disable or purge network-manager.

4. Restart your networking service: service network-manager restart

Network Manager

On newer systems, the Network Manager (Debian package: network-manager) is used instead of ifupdown (and its /etc/network/interfaces config file).

You can find the network configs in a keyfile (.ini format):

# /etc/NetworkManager/NetworkManager.conf

[main]
plugins=ifupdown,keyfile

[ifupdown]
managed=false  # false = ifupdown does not manage networks (Network Manager does)
               # true = ifupdown does manage networks

Multiple plugins: specify in a preference order using ',' as a separator. This will cause connections to be read from all listed plugins.

  • Example: plugins=ifupdown,keyfile uses both the traditional ifupdown configs from /etc/network/interfaces and keyfile connections from /etc/NetworkManager/system-connections.
    • When creating new connections, or making a user-settings connection into a system-settings connection, the plugins will be asked to save the connection in the order listed here.
    • If the first plugin cannot write out that connection type, or can't write out any connections, the next plugin is tried. If none of the plugins can save the connection, the error is returned to the user.
  • The 'keyfile' plugin is the generic plugin that supports all the connection types and capabilities that NM has. It writes files out in a .ini-style format in /etc/NetworkManager/system-connections.

Configuration File: The Network Manager configuration file can be found here (but you should use nmcli or, preferred, nmtui to configure a connection)

/etc/NetworkManager/system-connections/

Network Manager Tools (included with install):

  • nmcli : the dedicated command line tool used in order to configure, add, edit and remove connections using the Network Manager;
  • nmtui : (tab-complete to see shortcuts) a graphical user interface that provides just a subset of features compated to nmcli. Using nmtui, you can edit a connection, activate a connection or change the hostname of your computer;
  • nm-applet : available in GNOME desktop environments, this applet is used as an interface overlay which can be used in order to connect or disconnect from networks.

systemd-networkd

Loaded but inactive on a standard Debian install.

Reference: https://wiki.debian.org/SystemdNetworkd


Configs

You can set up as many network configs for as many interfaces as you want. Just set them up, comment them out, and when you want to use one remove the # and bring it up.

  • As root, edit: /etc/network/interfaces.
  • Note: Keep the loopback and everything else your *nix install put in there… you have been warned.
  • The following example assumes eth0 for wired network and wlan0 for wireless.

Alternative: Put each of your separate configs in its own file and use ifup –interfaces FILE and ifdown –interfaces FILE to use whichever you want.

  • Put a DHCP for home in one file and static in another.
  • Put multiple hackLab configs for WEP, WPA, etc. each in its own file and bring them up/down with ifupdown using -i FILE or –interfaces FILE option
# +-------------------------+ #
# | Wired Network Interface | #
# +-------------------------+ #

# Comment out these lines if you want to manually bring up your network
    allow-hotplug eth0  # bring up the interface on a hotplug event like plugging in a usb cable
    auto eth0           # bring up the interface on boot

## The following w/o auto or allow-hotplug requires manual up.

## [1] STATIC (replace subnet with your own):
#iface eth0 inet static
#    address   192.168.0.100
#    netmask   255.255.255.0
#    network   192.168.0.0
#    gateway   192.168.0.1
#    broadcast 192.168.0.255

## [2] DHCP (one or the other):
#iface eth0 inet dhcp  # IPv4
#iface eth0 inet6 auto # IPv6

# +----------------------------+ #
# | Wireless Network Interface | #
# +----------------------------+ #

# Comment out these lines if you want to manually bring up your network
    allow-hotplug wlan0
    auto wlan0

## The following w/o auto or allow-hotplug requires manual up.

## [1] STATIC (replace subnet with your own; either WEP or WPA/WPA2):

# WEP static
#iface wlan0 inet static
#    address        10.0.0.10
#    netmask        255.255.255.0
#    network        10.0.0.0
#    gateway        10.0.0.1
#    broadcast      10.0.0.255
#    wireless-essid SSID_of_Router
#    wireless-key   Not_the_Passphrase_TheKEY

## WPA/WPA2 static
#iface wlan0 inet static
#    address   10.0.0.10
#    netmask   255.255.255.0
#    network   10.0.0.0
#    gateway   10.0.0.1
#    broadcast 10.0.0.255
#    wpa-ssid  SSID_of_Router
#    wpa-psk   PassPhrase

## [2] DHCP (either WEP or WPA/WPA2):

## WEP dhcp
#iface wlan0 inet dhcp
#    wireless-essid SSID_of_Router
#    wireless-key   Not_the_Passphrase_TheKEY
    
## WPA/WPA2 dhcp
#iface wlan0 inet dhcp
#    wpa-ssid SSID_of_Router
#    wpa-psk  PassPhrase

general_network.1588090167.txt.gz · Last modified: by gman