无网不利
查看当前网络接口配置
# ifconfig
手动设置网络接口的IP地址
# ifconfig wlan0 192.168.1.1
使用下面命令设置ip地址和子网掩码
# ifconfig wlan0 192.168.0.80 netmask 255.255.255.0
自动配置网络接口:如果你链接到一个支持自动分配IP的有线网络中,使用下面命令就可直接配置网络接口了:
# dhclient eth0
打印网络接口卡列表
[root@node2 ~]# ifconfig | cut -c -10 |tr -d ' ' | tr -s '\n' cni0:flag docker0:f eth0:flag flannel.1: lo:flags=
......
显示IP地址
ifconfig默认显示系统中所有可用网络接口的详细信息。我们可以限制它只显示某个特定的接口信息:
# ifconfig iface_name 如下:
[root@node2 ~]# ifconfig eth0 eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 172.16.64.32 netmask 255.255.248.0 broadcast 172.16.71.255 ether 00:16:3e:00:09:72 txqueuelen 1000 (Ethernet) RX packets 12973032 bytes 4389941442 (4.0 GiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 12067316 bytes 1072781975 (1023.0 MiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@node2 ~]# ifconfig eth0 |egrep -o "inet [^ ]*" | grep -o "[0-9.]*"
172.16.64.32
硬件地址(MAC地址)欺骗
按照下面方法在软件层面上进行硬件地址欺骗 # ifconfig eth0 hw ether 00:1c:bf:87:25:d5
上面分配了新的MAC地址。如果我们需要通过部署了MAC认证的internet服务提供商才能访问internet,这招就能排上用场。注意:这在机器重启后就失效了。
名字服务器与DNS(域名服务)
互联网最常见的寻址方式是IP地址(采用点分十进制形式,例如202.11.32.75).然而internet上的资源(比如网址)是通过被称为URL或者域名的ASCII字符组合来访问的,例如google.com就是一个域名,它对应一个(或者多个)IP地址。在浏览器中输入IP地址同样可以访问www.google.com。
这种利用符号对IP地址进行抽象的技术叫做域名服务(DNS)。当我们输入网址,配置好DNS的服务器将域名解析成对应的IP地址。在本地网络中,我们可以设置本地DNS,以便使用主机名来命名本地网络中的主机。
分配给当前系统的名字服务器可以通过读取/etc/resolv.conf查看
[root@node2 ~]# cat /etc/resolv.conf options timeout:2 attempts:3 rotate single-request-reopen ; generated by /usr/sbin/dhclient-script nameserver 172.16.2.29 nameserver 172.16.2.7 nameserver 8.8.8.8 nameserver 114.114.114.114
我们可以手动添加名字服务器
# echo nameserver IP_ADDRESS >> /etc/resolv.conf
如何获取域名的IP地址呢?最简单的方法就是ping域名
[root@node2 ~]# ping www.baidu.com PING www.wshifen.com (103.235.46.39) 56(84) bytes of data. 64 bytes from 103.235.46.39 (103.235.46.39): icmp_seq=1 ttl=48 time=186 ms
DNS查找
host和nslookup是DNS查找工具
[root@iZr4s05capgvfej0ntls1zZ pipeline_test]# nslookup www.baidu.com Server: 223.5.5.5 Address: 223.5.5.5#53 Non-authoritative answer: www.baidu.com canonical name = www.a.shifen.com. Name: www.a.shifen.com Address: 220.181.38.150 Name: www.a.shifen.com Address: 220.181.38.149
[root@iZr4s05capgvfej0ntls1zZ pipeline_test]# host www.baidu.com www.baidu.com is an alias for www.a.shifen.com. www.a.shifen.com has address 220.181.38.150 www.a.shifen.com has address 220.181.38.149
如果不使用DNS服务器,也可以将IP地址和域名对应关系添加进/etc/hosts文件
# echo IP_ADDRESS symbolic_namme >> /etc/hosts
# echo 192.168.1.1 www.hanshengli.com >> /etc/hosts
显示路由表
[root@master ~]# route Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface default gateway 0.0.0.0 UG 0 0 0 eth0 10.244.0.0 0.0.0.0 255.255.255.0 U 0 0 0 cni0 10.244.1.0 10.244.1.0 255.255.255.0 UG 0 0 0 flannel.1 10.244.2.0 10.244.2.0 255.255.255.0 UG 0 0 0 flannel.1 link-local 0.0.0.0 255.255.0.0 U 1002 0 0 eth0 172.16.64.0 0.0.0.0 255.255.248.0 U 0 0 0 eth0 172.17.0.0 0.0.0.0 255.255.0.0 U 0 0 0 docker0
-n指定数字形式显示地址
[root@master ~]# route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 0.0.0.0 172.16.71.253 0.0.0.0 UG 0 0 0 eth0 10.244.0.0 0.0.0.0 255.255.255.0 U 0 0 0 cni0 10.244.1.0 10.244.1.0 255.255.255.0 UG 0 0 0 flannel.1 10.244.2.0 10.244.2.0 255.255.255.0 UG 0 0 0 flannel.1 169.254.0.0 0.0.0.0 255.255.0.0 U 1002 0 0 eth0 172.16.64.0 0.0.0.0 255.255.248.0 U 0 0 0 eth0 172.17.0.0 0.0.0.0 255.255.0.0 U 0 0 0 docker0
设置默认网关
# route add default gw IP_ADDRESS INTERFACE_NAME 例如 # route add default gw 192.168.0.1 eth0

浙公网安备 33010602011771号