1. 程式人生 > >3.21 10.11-10.15聽課筆記

3.21 10.11-10.15聽課筆記

設置虛擬ip iptables

Linux網絡相關

[root@localhost ~]# ifconfig

ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500

inet 192.168.91.128 netmask 255.255.255.0 broadcast 192.168.91.255

inet6 fe80::613e:a8bf:a776:7dbb prefixlen 64 scopeid 0x20<link>

ether 00:0c:29:58:49:a9 txqueuelen 1000 (Ethernet)

RX packets 105173 bytes 31378778 (29.9 MiB)

RX errors 0 dropped 0 overruns 0 frame 0

TX packets 279549 bytes 72836445 (69.4 MiB)

TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536

inet 127.0.0.1 netmask 255.0.0.0

inet6 ::1 prefixlen 128 scopeid 0x10<host>

loop txqueuelen 1 (Local Loopback)

RX packets 0 bytes 0 (0.0 B)

RX errors 0 dropped 0 overruns 0 frame 0

TX packets 0 bytes 0 (0.0 B)

TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

[root@localhost ~]# ip addr

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1

link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00

inet 127.0.0.1/8 scope host lo

valid_lft forever preferred_lft forever

inet6 ::1/128 scope host

valid_lft forever preferred_lft forever

2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000

link/ether 00:0c:29:58:49:a9 brd ff:ff:ff:ff:ff:ff

inet 192.168.91.128/24 brd 192.168.91.255 scope global ens33

valid_lft forever preferred_lft forever

inet6 fe80::613e:a8bf:a776:7dbb/64 scope link

valid_lft forever preferred_lft forever

[root@localhost ~]# ifdown ens33

Connection closed by foreign host.

Disconnected from remote host(hyclinux-01) at 22:31:38.

Type `help' to learn how to use Xshell prompt.

執行後連接斷開

[root@localhost ~]# ifup ens33

*ifdownifup可以在修改指定網卡配置後重啟指定的網卡

[root@localhost ~]# ifdown ens33 && ifup ens33

成功斷開設備 'ens33'

連接已成功激活(D-Bus 活動路徑:/org/freedesktop/NetworkManager/ActiveConnection/3

設置虛擬網卡

[root@localhost ~]#

在網卡配置文件目錄下拷貝ifcfg-ens33文件,更名為ifcfg-ens330,做如下修改:

TYPE=Ethernet

PROXY_METHOD=none

BROWSER_ONLY=no

BOOTPROTO=static

DEFROUTE=yes

IPV4_FAILURE_FATAL=no

IPV6INIT=yes

IPV6_AUTOCONF=yes

IPV6_DEFROUTE=yes

IPV6_FAILURE_FATAL=no

IPV6_ADDR_GEN_MODE=stable-privacy

NAME=ens33:0

UUID=32826281-32dd-4e88-af97-8176b8eb1eee

DEVICE=ens33:0

ONBOOT=yes

IPADDR=192.168.91.131

NETMASK=255.255.255.0

GATEWAY=192.168.91.2

[root@localhost ~]# ifconfig

ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500

inet 192.168.91.128 netmask 255.255.255.0 broadcast 192.168.91.255

inet6 fe80::613e:a8bf:a776:7dbb prefixlen 64 scopeid 0x20<link>

ether 00:0c:29:58:49:a9 txqueuelen 1000 (Ethernet)

RX packets 107714 bytes 31619328 (30.1 MiB)

RX errors 0 dropped 0 overruns 0 frame 0

TX packets 281528 bytes 73182413 (69.7 MiB)

TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

ens33:0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500

inet 192.168.91.131 netmask 255.255.255.0 broadcast 192.168.91.255

ether 00:0c:29:58:49:a9 txqueuelen 1000 (Ethernet)

lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536

inet 127.0.0.1 netmask 255.0.0.0

inet6 ::1 prefixlen 128 scopeid 0x10<host>

loop txqueuelen 1 (Local Loopback)

RX packets 0 bytes 0 (0.0 B)

RX errors 0 dropped 0 overruns 0 frame 0

TX packets 0 bytes 0 (0.0 B)

TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

[root@localhost ~]# mii-tool ens33 兩個命令均可查看網卡是否連接(網線)

ens33: negotiated 1000baseT-FD flow-control, link ok

[root@localhost ~]# ethtool ens33

Settings for ens33:

Supported ports: [ TP ]

Supported link modes: 10baseT/Half 10baseT/Full

100baseT/Half 100baseT/Full

1000baseT/Full

Supported pause frame use: No

Supports auto-negotiation: Yes

Advertised link modes: 10baseT/Half 10baseT/Full

100baseT/Half 100baseT/Full

1000baseT/Full

Advertised pause frame use: No

Advertised auto-negotiation: Yes

Speed: 1000Mb/s

Duplex: Full

Port: Twisted Pair

PHYAD: 0

Transceiver: internal

Auto-negotiation: on

MDI-X: off (auto)

Supports Wake-on: d

Wake-on: d

Current message level: 0x00000007 (7)

drv probe link

Link detected: yes

問題:

[root@localhost ~]# cat /etc/resolv.conf

; generated by /usr/sbin/dhclient-script

search localdomain

nameserver 192.168.91.2

如果在這個文件裏修改dns,重啟機器後該文件的配置會被網卡配置文件中的dns覆蓋

[root@localhost ~]# cat /etc/hosts 訪問自定義域名時使用(自定義域名對應的ip

127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4

::1 localhost localhost.localdomain localhost6 localhost6.localdomain6

[root@localhost ~]# vim /etc/hosts

[root@localhost ~]# ping www.baidu.com

PING www.baidu.com (127.0.0.1) 56(84) bytes of data.

64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.070 ms

64 bytes from localhost (127.0.0.1): icmp_seq=2 ttl=64 time=0.085 ms

64 bytes from localhost (127.0.0.1): icmp_seq=3 ttl=64 time=0.085 ms

64 bytes from localhost (127.0.0.1): icmp_seq=4 ttl=64 time=0.069 ms

64 bytes from localhost (127.0.0.1): icmp_seq=5 ttl=64 time=0.074 ms

64 bytes from localhost (127.0.0.1): icmp_seq=6 ttl=64 time=0.067 ms

^Z

[1]+ 已停止 ping www.baidu.com

[root@localhost ~]# cat /etc/hosts

127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4

::1 localhost localhost.localdomain localhost6 localhost6.localdomain6

127.0.0.1 www.baidu.com

*可以支持一個ip對應多個域名

Hosts文件中一個域名配多個ip時以最後配置的對應關系為主


3.21 10.11-10.15聽課筆記