There are three ways of network configuration in Linux: ifconfig command temporarily configure IP address, setup tool permanently configure IP address, modify network configuration file
1, ifconfig command: view and configure network status
[plain] view plain copy
[root@SZB-L0016229 ~]# ifconfig
eth0 Link encap:Ethernet HWaddr 06:3F:84:00:1A:1D //ethernet represents Ethernet Hwaddr is mac address
inet addr:172.30.17.66 Bcast :172.30.17.255 Mask:255.255.254.0 //ip address broadcast address subnet mask
inet6 addr: fe80::43f:84ff:fe00:1a1d/64 Scope:Link //ipv6
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:157925291 errors:0 dropped:0 overruns:0 frame:0 //received packets
TX packets:84629081 errors:0 dropped:0 overruns:0 carrier:0 //send packets
collisions:0 txqueuelen:1000
RX bytes: 19957269874 (18.5 GiB) TX bytes: 13934822757 (12.9 GiB)
lo Link encap: Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:39123 errors:0 dropped:0 overruns:0 frame:0
TX packets: 39123 errors: 0 dropped: 0 overruns: 0 carrier: 0
collisions: 0 txqueuelen: 0
RX bytes: 2257978 (2.1 MiB) TX bytes: 2257978 (2.1 MiB)
lo stands for loopback, loopback address, means the current computer itself, no need to pay attention
eth0 represents a network card, if there are two there will be eth1.
ifconfig eth0 192.168.0.200 netmask 255.255.255.0 // Temporarily set the IP address and subnet mask of the eth0 network card
2. Use the setup tool to configure the network:
setup is a tool exclusive to redhat series linux, you can start configuring the network by typing the setup command directly in the command.
3. Configure the network through the file
vi /etc/sysconfig/network-scripts/ifcfg-eth0 (network card information file)
[plain] view plain copy
DEVICE=eth0 //The name of the network card device
TYPE=Ethernet //The type is Ethernet
ONBOOT=yes //Whether eth0 is started with the network service to take effect? This configuration must be manually changed to yes
NM_CONTROLLED=no //Whether it is controlled by graphics Interface configuration hosting
BOOTPROTO=dhcp //Whether to automatically obtain ip dhcp is to obtain automatically If it is none, you also need to configure ip dns mask gateway, etc.
vi /etc/sysconfig/network (hostname file)
NETWORKING=yes
This item in the file needs to be set to yes
vi /etc/resole.conf (DNS configuration file)
nameserver 172.30.255.24
nameserver 172.30.255.25
Configure DNS server
sevice network restart (you need to restart the network configuration after modifying the network configuration)
Linux network related commands:
1, ifconfig view and configure ip, mask
2, ifdown network card device name / ifup network card device name Disable and start the network card
3, netstat view port occupancy
-t: List TCP protocol ports
-u: List UDP protocol ports
-l: list all listening ports
-n: output as ip and port
-a: list all
Commonly used netstat -tuln; netstat -an
4. View the gateway: route -n can also use netstat -rn
5, nslookup for domain name and ip translation
[plain] view plain copy
[root@SZB-L0016229 ~]# nslookup www.qq.com
Server: 172.30.255.24 //The DNS server
Address: 172.30.255.24#53
Non-authoritative answer: //View the corresponding domain name IP
Name: www.qq.com
Address: 101.226.103.106
6, ping [option] ip or domain name
to test network connectivity, the premise is that the server allows others to ping. Add -c times: specify the number of pings
7. Telnet domain name or ip port for remote management or port detection
Telnet only adds a domain name or ip for remote management, and the server needs to enable the telnet remote management service. It will not be enabled by default.
Telnet domain name or ip port is a detection port, which can be used for whether the other party has opened the service of this port or whether there is a firewall
8, traceroute domain name or ip: used for route tracing
9, wget download file address: linux download command
10 , tcpdump -i eth0 -nnX port 21
Listening command -i specifies the network card as eth0 -nn Converts the domain name in the package to an ip port Display X16 hex display port listening port
This command can be used to capture packets on the server side