linux rookie basic learning (6) network

Keywords: Linux network vim DNS firewall

Network configuration under linux

1. What is IP ADDRESS

  internet protocol ADDRESS ##Network Protocol Address
    ipv4    internet protocol version 4
    1.2x32
    ip It consists of 32 zeros and 1.
    11111110.11111110.11111110.11111110 = 254.254.254.254

2. Subnet mask

Used to divide the network area
 The number on the ip corresponding to the non-zero bit of the subnet mask represents the network bit of the ip
 The number corresponding to 0 bits of subnet mask is the host bit of ip
 Network bits represent network areas
 Host bit represents a host in a network area

3.ip communication decision

Two IP s with the same network bit and inconsistent host bit can communicate directly.
172.25.254.1/24     24=255.255.255.0
172.25.254.2/24
172.25.0.1/16

4. Network Setting Tools

ping        ##Detect whether the network is unobstructed
ifconfig    ##View or set the network interface
ifconfig device ip/24   ##Setting up network
ifconfig device down    ##Close
ifconfig device up  ##open

5. Setting ip graphically

1.nm-connection-editor

2.nmtui

6. Command Setting Network

nmcli

nmcli device connect eth0   ##Enabling eth0 network card
nmcli device disconnect eth0    ##Turn off eth0 network card
nmcli device show eth0      ##View Network Card Information
nmcli device status eth0    ##View Network Card Service Interface Information

nmcli connection show
nmcli connection down westos
nmcli connection up westos
nmcli connection delete westos
nmcli connection add type ethernet con-name westos ifname eth0 ip4 172.25.254.100/24
nmcli connection modify westos ipv4.method auto
nmcli connection modify westos ipv4.method manual
nmcli connection modify westos ipv4.addresses 172.25.254.150/24

7. Manage network configuration files

Network Configuration Directory
/etc/sysconfig/network-scripts
//Naming rules for network configuration files
ifcfg-xxx
DEVICE=xxx          ##Device name
BOOTPROTO=dhcp|static|none  ##Working mode of equipment
ONBOOT=yes          ##Automatic activation of network card when network service is on
IPADDR=             ##IP address
PREFIX=24           ##Subnet mask
NETMASK=255.255.255.0       ##Subnet mask

//Example:
//Static Network Settings File
vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
ONBOOT=yes
IPADDR=172.25.254.100
NETMASK=255.255.255.0
BOOTPROTO=none
NAME=westos

systemctl restart network

Configuration of multiple network cards on a single network card IP
vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
ONBOOT=yes
IPADDR0=172.25.254.100
NETMASK0=255.255.255.0
BOOTPROTO=none
NAME=westos
IPADDR1=172.25.0.100
PREFIX1=24

systemctl restart network

ip addr show eth0

8.lo loopback interface

9. gateway

1.Turn Real Host into Router

firewall-cmd --list-all
firewall-cmd --permanent --add-masquerade
firewall-cmd --reload

2.Setting up Virtual Machine Gateway
vim /etc/sysconfig/network
GATEWAY=172.25.254.250

10. set dns

doamin name system

vim /etc/hosts          ##Local parsing file
ip      domain name
61.135.169.121  www.baidu.com

vim /etc/resolv.conf        ##dns points to files
nameserver  114.114.114.114

vim /etc/sysconfig/network-scripts/ifcfg-eth0
DNS1=114.114.114.114

11. Setting Parsing Priority

System default
/etc/hosts > /etc/resolv.conf

vim /etc/nsswitch.conf
39 hosts:   files   dns ##/etc/hosts first

vim /etc/nsswitch.conf
39 hosts:       dns files     ##/etc/resolv.conf priority

12.dhcp service configuration

Posted by agent007 on Tue, 29 Jan 2019 09:30:15 -0800