Linux Basic network Settings

Source: Internet
Author: User
Tags nameserver nslookup nslookup command

# # # One, Linux basic network settings
# # # 1, view and test the network

##### 1) View network configuration
-**ifconfig Command * *
```
Ifconfig//view Active network interface information

```
* * Network Card Knowledge Introduction: * *

Eth0, lo: network interface name

HWADDR: Network card MAC Address

inet addr: IP address of the network interface

Bcast: The broadcast address of the network where the network interface resides

Mask: Subnet mask for network interface


```
[Email protected] ~]# ifconfig
Eth0 Link encap:ethernet HWaddr 00:0c:29:b2:44:8f
inet addr:192.168.1.125 bcast:192.168.1.255 mask:255.255.255.0
Inet6 ADDR:FE80::20C:29FF:FEB2:448F/64 Scope:link
Up broadcast RUNNING multicast mtu:1500 metric:1
RX packets:132226 errors:0 dropped:0 overruns:0 frame:0
TX packets:23844 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:12420847 (11.8 MiB) TX bytes:14671857 (13.9 MiB)

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:2 errors:0 dropped:0 overruns:0 frame:0
TX packets:2 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:104 (104.0 b) TX bytes:104 (104.0 b)


```




To view the interface information for all network cards:

Ifconfig-a

To view the interface information for a piece of Nic:

Ifconfig eth0
-**ip/ethtool Command * *

```
IP link//View data link layer information for all network interfaces
IP link Show eth0//View Data link layer information for a specified NIC

```
```
IP address//view network layer information for all network interfaces
IP address show eth0//view network layer information for the specified network card
```
```
Ethtool eth0//View physical attribute information such as rate, mode, etc. for a specified network interface
```

```
[[Email protected] ~]# IP link
1:lo: <LOOPBACK,UP,LOWER_UP> MTU 16436 qdisc noqueue State UNKNOWN
Link/loopback 00:00:00:00:00:00 BRD 00:00:00:00:00:00
2:eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> MTU Qdisc pfifo_fast State up Qlen 1000
Link/ether 00:0c:29:b2:44:8f BRD FF:FF:FF:FF:FF:FF
[[Email protected] ~]# IP addr
1:lo: <LOOPBACK,UP,LOWER_UP> MTU 16436 qdisc noqueue State UNKNOWN
Link/loopback 00:00:00:00:00:00 BRD 00:00:00:00:00:00
inet 127.0.0.1/8 Scope host Lo
INET6:: 1/128 Scope Host
Valid_lft Forever Preferred_lft Forever
2:eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> MTU Qdisc pfifo_fast State up Qlen 1000
Link/ether 00:0c:29:b2:44:8f BRD FF:FF:FF:FF:FF:FF
inet 192.168.1.125/24 BRD 192.168.1.255 Scope Global eth0
Inet6 FE80::20C:29FF:FEB2:448F/64 Scope link
Valid_lft Forever Preferred_lft Forever
```
-**hostname/route Command * *

```
[[email protected] ~]# hostname//View host name
Test2
```
```
[[email protected] ~]# route//View routing table
Kernel IP Routing Table
Destination Gateway genmask Flags Metric Ref use Iface
192.168.1.0 * 255.255.255.0 U 0 0 0 eth0
link-local * 255.255.0.0 U 1002 0 0 eth0
Default localhost 0.0.0.0 UG 0 0 0 eth0
[[email protected] ~]# route-n//View routing table, all with IP address display
Kernel IP Routing Table
Destination Gateway genmask Flags Metric Ref use Iface
192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 1002 0 0 eth0
0.0.0.0 192.168.1.1 0.0.0.0 UG 0 0 0 eth0
```
-**netstat Command * *

viewing Network Connections = = (e.g. port monitoring) = =

Options | Role
---|---
-A | Displays network connection information for all activities in the current host
-N | Display related information in digital form
-r | Show routing table information
-T | Displaying TCP protocol-related information
-u | displaying UDP protocol-related information
-L | Display the service information in the listening
-P | Displays the process number, process name information associated with the network connection (requires root permission)

Typically use the "-ANPT", "UTPLN" combination options


```
[[email protected] ~]# NETSTAT-ANPT |grep SSH
TCP 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 2122/sshd
TCP 0 192.168.1.125:22 192.168.1.109:50992 established 47349/sshd
TCP 0 0::: $:::* LISTEN 2122/sshd
[[email protected] ~]# NETSTAT-UTPLN |grep SSH
TCP 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 2122/sshd
TCP 0 0::: $:::* LISTEN 2122/sshd
```


##### 2) test network connection

-**ping/traceroute/nslookup Command * *

```
Ping//test network connectivity
-c//Specify the number of packets
```
```
Traceroute//routing path for tracking packets
```

```
[Email protected] ~]# traceroute 192.168.1.101
Traceroute to 192.168.1.101 (192.168.1.101), hops max, byte packets
1 localhost (192.168.1.125) 3006.931 MS! H 3006.930 MS! H 3006.927 MS! H

```

```
Nslookup//Testing DNS domain name resolution
```

```
[[email protected] ~]# nslookup www.baidu.com//Resolve a domain name directly
server:202.106.195.68//Resolved server
ADDRESS:202.106.195.68#53//parsing the port of the service

Non-authoritative Answer:
www.baidu.com canonical name = www.a.shifen.com.
Name:www.a.shifen.com
address:61.135.169.121
Name:www.a.shifen.com
address:61.135.169.125

[[email protected] ~]# nslookup www.baidu.com 8.8.8.8//You can also specify a server to parse
server:8.8.8.8
address:8.8.8.8#53

Non-authoritative Answer:
www.baidu.com canonical name = www.a.shifen.com.
Name:www.a.shifen.com
address:61.135.169.121
Name:www.a.shifen.com
address:61.135.169.125

```




# # 2, set network address parameters

##### 1) Using the Network configuration command

In a Linux environment, there are two basic ways to manually modify a network configuration:

-Temporary configuration:

Direct modification through the command, the modification can take effect immediately, generally used to debug the network, restart the service or host will be invalid;

```
Ifconfig eth0 192.168.1.10 netmask 255.255.255.0 Gateway 192.168.1.1
```

```
Ifconfig eth0 up//enable Eth0 network interface
Ifconfig eth0 down//disable Eth0 network interface
```

```
IFCONIFG eth0:0 10.10.10.10//Bind virtual interface for NIC
```


-Fixed configuration:

By modifying the parameters in the configuration file, the service needs to be restarted before it takes effect; "Permanent configuration"

```
Vi/etc/sysconfig/network-scripts/ifcfg-eth0
```

To modify the host name using the hostname command:


```
Hostname deeption//Temporary settings
```

To add and remove static routes using the route command:

-Specify the route for the network segment:

```
Route add-net 192.168.2.0/24 GW x.x.x.x//Add
Route del-net 192.168.2.0/24//delete
```

-Default route (Gateway):

```
Route add default GW x.x.x.x//Add
Route del default GW x.x.x.x//delete
Route | grep default//view defaults route
```


##### 2) Modify the network configuration file

The configuration file of the network interface is located by default in the directory "/etc/sysconfig/network-scripts/", the file name format is "Ifcfg-xxx", where "XXX" is the name of the network interface, such as Eth0, lo

-Permanently set the network interface configuration:
```
Vi/etc/sysconfig/network-scripts/ifcfg-eth0
```

```
Network interface configuration file contents:
Device=eth0//network Interface Device name
Type=ethernet
uuid=adf9d271-d77d-4b4c-a4fd-58eb0c85d663
Onboot=yes//Set Boot active
Nm_controlled=no//General set to No, indicates that the System Network management tool does not control this NIC
Bootproto=static//Set static IP address or DHCP
Defroute=yes
Ipv4_failure_fatal=yes
Ipv6init=no
Name= "System eth0"
hwaddr=00:0c:29:b2:44:8f
last_connect=1462590913
IPADDR=192.168.1.125//Set IP address
netmask=255.255.255.0//Set subnet mask
gateway=192.168.1.1//Set default gateway
```
-Command to restart the network service:

```
Service network restart//will restart all networking interfaces
```
-Restart a network interface command:

```
Ifdown eth0
Ifup eth0
```
Note: The temporarily configured subinterface disappears after the NIC restarts

-Permanently set host name:

```
Vi/etc/sysconfig/network
```

```
Hostname Configuration file Contents:
Networking=yes
Hostname=test2

```
-Permanently set the domain name resolution server:
```
Vi/etc/resolv.conf
```
```
Domain name resolution configuration file contents:
NameServer 202.106.195.68//dns Server, parsing sequence is used from top to bottom
NameServer 202.106.46.151
```
-Local Host mapping File (hosts):

The >/etc/hosts file records a mapping relationship table of hostname and IP address, which is commonly used to store host information that is often needed for access.

> When accessing an unknown domain name, first find the Hosts file, if not to ask the DNS server.

```
[Email protected] ~]# cat/etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.local
:: 1 localhost localhost.localdomain localhost6 localhost6.loca
Alias name alias for IP address domain name
```



The above is the simplest network knowledge ╮ ( ̄▽ ̄) ╭



! [] (Http://i.imgur.com/4VbBTLB.gif)







This article is from the "11544947" blog, please be sure to keep this source http://11554947.blog.51cto.com/11544947/1793780

Linux Basic network Settings

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.