linux_wiki:configure_networking_and_hostname_resolution_statically_or_dynamically

This is an old revision of the document!


Configure Networking And Hostname Resolution Statically Or Dynamically

General Information

Networking has changed from RHEL 6 to 7. You can still edit network scripts in /etc/sysconfig/network-scripts/, but the “preferred” method is using front end tools that tie into the NetworkManager service.


Show IP Address of Devices

ip addr show
  • ifconfig is deprecated in RHEL 7.


Show all Established Connections

ss


Show Established and Listening TCP Connections

ss -ant

flags:

  • a ⇒ show both established and listening
  • t ⇒ show tcp connections
  • n ⇒ do not resolve service names (ports)


Other tools to use:

  • ping -c 5 (send 5 pings)
  • traceroute
  • tracepath
  • netstat - netstat has been deprecated (use ss instead), but can still be installed as part of the net-tools package

NetworkManager is the default network service in RHEL 7.

  • Main Service = NetworkManager.service
  • Tools to interface with NetworkManager
    • nm-connection-editor (GUI)
    • nmtui (ncurses based)
    • nmcli (cli)
  • Fallback service = network.service
    • This uses the traditional network scripts in /etc/sysconfig/network-scripts/ as a fallback if NetworkManager is not in control of an interface.


Open GUI for network connections (GUI Only)

nm-connection-editor


Open text based wizard

nmtui


nmcli makes configuration changes to files in: /etc/sysconfig/network-scripts/

These files can alternatively be modified manually.


Network Device Status

nmcli dev status


Show all connection configurations

nmcli con show
  • Configurations location: /etc/sysconfig/network-scripts/


Example: Create new connection (dhcp)

nmcli con add con-name "mycon" autoconnect yes type ethernet ifname eth1


Example: Create new connection (static ip)

nmcli con add con-name "mycon-static" autoconnect yes type ethernet ifname eth1 ip4 10.0.0.5/24 gw4 10.0.0.254
  • The above produces the following config:
    • /etc/sysconfig/network-scripts/ifcfg-mycon-static
    • TYPE=Ethernet
      BOOTPROTO=none
      IPADDR=10.0.0.5
      PREFIX=24
      GATEWAY=10.0.0.254
      DEFROUTE=yes
      IPV4_FAILURE_FATAL=no
      IPV6INIT=yes
      IPV6_AUTOCONF=yes
      IPV6_DEFROUTE=yes
      IPV6_PEERDNS=yes
      IPV6_PEERROUTES=yes
      IPV6_FAILURE_FATAL=no
      NAME=mycon-static
      UUID=f7e0c9af-715d-43da-9576-e6ce218d0c28
      DEVICE=eth1
      ONBOOT=yes


Show only active connections

nmcli con show --active


Bring connections up/down

nmcli con down "mycon-static"
nmcli con up "mycon"


Change an existing connection's IP and Gateway

nmcli con mod eth0 ipv4.addresses 192.168.1.50/24
nmcli con mod etho ipv4.gateway 192.168.1.254
nmcli con up eth0

View current hostname

hostname


Set temporary(transient) hostname

hostname myserver.domain.com
exec bash


View detailed hostname information

hostnamectl
  • static hostname (stored in: /etc/hostname) - used to initialize kernel at boot (persistent)
  • transient hostname - assigned temporarily due to network configuration, may revert back to static if network connectivity is lost
  • pretty hostname (stored in: /etc/machine-info) - little restrictions on characters used


Set persistent(static) hostname

hostnamectl set-hostname myserver.com


Order of name resolution

/etc/nsswitch.conf


System wide dns name server entries (static or network manager generated)

/etc/resolv.conf
 
# Generated by NetworkManager
search us-west-2.compute.internal
nameserver 172.31.0.2


Local system hostname resolution and example entry

/etc/hosts
 
10.1.1.2  myserver.com


Add DNS for eth0 with nmcli or with config file

nmcli con show
(observe NAME field)
nmcli con mod "System eth0" +ipv4.dns 8.8.8.8

OR

vim /etc/sysconfig/network-scripts/ifcfg-eth0
 
DNS1=8.8.8.8
  • Both methods require the NetworkManager service to be restarted for changes to take effect. (systemctl restart NetworkManager)

  • linux_wiki/configure_networking_and_hostname_resolution_statically_or_dynamically.1457062375.txt.gz
  • Last modified: 2019/05/25 23:50
  • (external edit)