Linux Network - yenbohuang/techNotes GitHub Wiki

Edit hosts file

sudo nano /etc/hosts

See details on http://www.rackspace.com/knowledge_center/article/how-do-i-modify-my-hosts-file

List all listening port

netstat -anp

See details on https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/3/html/Security_Guide/s1-server-ports.html

List NAT port forwarding information

sudo iptables -t nat -L -n

See details on http://ipset.netfilter.org/iptables.man.html

SSH

Enable SSH server

Ubuntu

sudo apt-get install openssh-server 
sudo service sshd start

CentOS

sudo service sshd start

See details on https://lecturesnippets.com/lesson/setting-up-ssh-server-in-centos-7-minimal-install/

Enable root login over SSH

This is a bad practice. Do not enable root login in production environment.

CentOS

  • Open /etc/ssh/sshd_config and change:
    • PermitRootLogin yes
    • PasswordAuthentication yes
  • sudo service sshd restart

See details on:

/etc/resolv.conf

Ubuntu

  • Add nameserver in this file
sudo nano /etc/resolvconf/resolv.conf.d/head
  • Add search in this file
sudo nano /etc/resolvconf/resolv.conf.d/tail
  • Update
sudo resolvconf -u

See details on http://www.lampnode.com/linux/howto-setup-nameserver-on-ubuntu-1404-by-resolvconf/

CentOS

  • Make nameserver permanent

Add PEERDNS=no to /etc/sysconfig/network-scripts/ifcfg-***.

See details on https://www.centos.org/forums/viewtopic.php?t=62970

Mounting network drive by samba

sudo mount -t cifs \
     -o username=${name},password=${pwd},uid=${uid},gid=${gid} \
     ${network path} ${local path}

See details on http://unix.stackexchange.com/questions/68079/mount-cifs-network-drive-write-permissions-and-chown

SCP

scp SourceFile user@host:directory/TargetFile
scp user@host:directory/SourceFile TargetFile

See details on http://webdev.gmu.edu/uploading-files-with-secure-copy-scp/.

Firewall settings

CentOS

Configure the Firewall Using the Command Line:

sudo lokkit --port=123:udp --update

Checking Network Access for Incoming NTP Using the Command Line

sudo less /etc/sysconfig/system-config-firewall

See details on https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Deployment_Guide/s2-Configure_the_Firewall_Using_the_CLI.html.

curl command

HTTP PUT

curl -v -X PUT -d <content> http://localhost/api/handler

Download file

curl http://localhost/somefile.zip > /tmp/myfile.zip

Using fixed IP address

CentOS

  • Use ifconfig and know which NIC we are updating.
  • Open /etc/sysconfig/network-scripts/ifcfg-??? and change:
    • BOOTPROTO=none
    • ONBOOT=yes
    • DNS1=???
    • DOMAIN=??
    • IPADDR=??
    • PREFIX=24
    • GATEWAY=??
  • sudo systemctl restart network

Or, use UI tool:

sudo nmtui

See details on:

Using DHCP address

CentOS

After installing CentOS in Virtual Box, the VM is not ready to use NAT network connection. We need to enable DHCP and restart network.

  • Edit this config file:
sudo nano /etc/sysconfig/network-scripts/ifcfg-enp3s0
  • Add the following configurations:
DEVICE=enp3s0
ONBOOT=yes
DHCP=yes
  • Restart network:
sudo ifdown enp0s3
sudo ifup enp0s3

See details on:

Check DNS and flush DNS cache

sudo systemd-resolve --flush-caches
dig <FQDN>

See details on:

Check hostname by IP

Intranet

nmblookup -A <IP address>

Internet

nslookup <IP address>
⚠️ **GitHub.com Fallback** ⚠️