索引 | 说明 |
网络配置常用 | 网络接口设定,IP地址设定,MAC与接口名修改,DHCP动态IP,静态IP,命名主机名,环回地址设定 |
IP网络基础 | IP网络初级知识,底层网络设置,DHCP配置网络接口,PPP,WLANi等配置 |
常用配置命令 | 常用配置命令 |
实战 | |
网络故障排除基础 |
网络配置:
1.Ethernet Interfaces网络接口地址:
Ethernet interfaces are identified by the system using the naming convention of ethX, where X represents a numeric value. The first Ethernet interface is typically identified as eth0, the second as eth1, and all others should move up in numerical order.
查找方式:
ifconfig -a | grep eth eth0 Link encap:Ethernet HWaddr 00:15:c5:4a:16:5a
或者#sudo lshw -class network
网络即可逻辑命名或者MAC地址设定:/etc/udev/rules.d/70-persistent-net.rules,NAME,ATTR{address}分别代表逻辑命名与MAC地址。
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:15:c5:4a:16:5a", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:15:c5:4a:16:5b", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth1"
网络接口设定工具:
sudo apt-get install ethtool
sudo ethtool eth0
2. IP地址设定:工具ip, ifconfig and route,
sudo ifconfig eth0 10.0.0.100 netmask 255.255.255.0
ifconfig eth0
修改默认网关
sudo route add default gw 10.0.0.1 eth0
查看修改
route -n
配置DNS服务。
If you require DNS for your temporary network configuration, you can add DNS server IP addresses in the file/etc/resolv.conf. The example below shows how to enter two DNS servers to/etc/resolv.conf, which should be changed to servers appropriate for your network. A more lengthy description of DNS client configuration is in a following section.
nameserver 8.8.8.8
nameserver 8.8.4.4
清除所有IP配置ip addr flush eth0
3. DHCP Client: Dynamic IP Address Assignment (DHCP Client)动态IP
To configure your server to use DHCP for dynamic address assignment, add the dhcp method to the inet address family statement for the appropriate interface in the file/etc/network/interfaces.The example below assumes you are configuring your first Ethernet interface identified as eth0.
auto eth0
iface eth0 inet dhcp
By adding an interface configuration as shown above, you can manually enable the
interface through the ifup command which initiates the DHCP process via dhclient.
sudo ifup eth0
sudo ifdown eth0
4.静态IP:
配置文件:/etc/network/interfaces
auto eth0
iface eth0 inet static
address 10.0.0.100
netmask 255.255.255.0
gateway 10.0.0.1
然后
sudo ifup eth0
sudo ifdown eth0
5.环回地址:Loopback Interface
环回地址的标识为:lo,IP地址为:127.0.0.1
查看:ifconfig lo
配置/etc/network/interfaces:
auto lo
iface lo inet loopback
6.Name Resolution
处理从IP地址到主机名的映射。
DNS client配置:
/etc/resolv.conf
a server on the domain "example.com" and using two public DNS servers.
search example.com
nameserver 8.8.8.8
nameserver 8.8.4.4
search example.com sales.example.com dev.example.com
nameserver 8.8.8.8
nameserver 8.8.4.4
静态主机名:
配置文件:/etc/hosts,IP到主机名的映射。
127.0.0.1 localhost
127.0.1.1 ubuntu-server
10.0.0.11 server1.example.com server1 vpn
10.0.0.12 server2.example.com server2 mail
10.0.0.13 server3.example.com server3 www
10.0.0.14 server4.example.com s