网络配置文件,/etc/network/interfaces 您所在的位置:网站首页 linux配置网络配置文件在哪打开的 网络配置文件,/etc/network/interfaces

网络配置文件,/etc/network/interfaces

2024-04-27 16:15| 来源: 网络整理| 查看: 265

如发现译文有瑕疵,请点击左边工具栏『纸飞机』按钮改进。

从命令行配置网络接口是很好的,但现在是时候学习如何让vm1自动配置网络接口。为此,你将了解/etc/network/interfaces配置文件:

user1@vm1:~$ cat /etc/network/interfaces # This file describes the network interfaces available on your system # and how to activate them. For more information, see interfaces(5). # The loopback network interface #(1) (2) auto lo #(3) (4)(5) (6) iface lo inet loopback # The primary network interface #(7) (8) allow-hotplug eth0 #(9) (10) (11) (12) iface eth0 inet dhcp

像往常一样,字段及其描述:

字段 描述 (1) 自动配置界面。 (2) 接口名称。 (3) 接口配置的开始 (4) 要配置的接口名称 (5) 此接口使用 TCP/IP 网络,IPv4。 (6) 它是回送接口。默认回送地址将自动分配给它。 (7) 在可用时自动配置接口(请在这里考虑 usb-modem)。 (8) 接口名称。 (9) 接口配置的开始 (10) 要配置的接口名称 (11) 此接口使用 TCP/IP 网络,IPv4。 (12) 此接口通过 DHCP 自动获取其参数。

其他包含网络配置的重要文件,但我们在这里不会碰到他们:

/etc/hosts - 操作系统中使用的计算机文件,用于将主机名映射到 IP 地址。hosts文件是一个纯文本文件,通常按照惯例命名为hosts。 /etc/hostname - 分配给连接到计算机网络的设备的标签,并用于识别各种形式的电子通信设备。 /etc/resolv.conf - 各种操作系统中的计算机文件,用于配置域名系统( DNS)解析器库。该文件是纯文本文件,通常由网络管理员或管理系统配置任务的应用创建。resolvconf程序是 linux 机器上的这样的程序,它管理resolv.conf文件。

让我们回忆之前练习的tap0。如果你重新启动vm1, 它就会消失。当然,你可以通过重新输入相关命令来启用它,但是让我们想象一下,你需要在重新启动后自动使用该命令。

现在,你将学习如何使用/etc/network/interfaces文件来配置接口。

这样做 1: ip a s 2: sudo vim /etc/network/interfaces

现在将这些东西添加到配置文件末尾:

3: auto tap0 4: iface tap0 inet static 5: address 10.1.1.2 6: netmask 255.255.255.0 7: tunctl_user uml-net 8: 9: allow-hotplug tap1 10: iface tap1 inet static 11: address 10.1.1.3 12: netmask 255.255.255.0

现在键入:wq并继续:

13: sudo /etc/init.d/networking start 14: ip a s 15: sudo tunctl -t tap1 -u uml-net 16: ip a s 你会看到什么 user1@vm1:~$ ip a s 1: lo: 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: mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 08:00:27:d4:45:68 brd ff:ff:ff:ff:ff:ff inet 10.0.2.15/24 brd 10.0.2.255 scope global eth0 inet6 fe80::a00:27ff:fed4:4568/64 scope link valid_lft forever preferred_lft forever user1@vm1:~$ sudo vim /etc/network/interfaces # and how to activate them. For more information, see interfaces(5). # The loopback network interface auto lo iface lo inet loopback # The primary network interface allow-hotplug eth0 iface eth0 inet dhcp auto tap0 iface tap0 inet static address 10.2.2.2 netmask 255.255.255.0 tunctl_user uml-net allow-hotplug tap1 iface tap1 inet static address 10.3.3.3 netmask 255.255.255.0 ~ "/etc/network/interfaces" 21L, 457C written 21,1-8 Bot user1@vm1:~$ sudo /etc/init.d/networking start Configuring network interfaces...Set 'tap0' persistent and owned by uid 104 done. user1@vm1:~$ ip a s 1: lo: 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: mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 08:00:27:d4:45:68 brd ff:ff:ff:ff:ff:ff inet 10.0.2.15/24 brd 10.0.2.255 scope global eth0 inet6 fe80::a00:27ff:fed4:4568/64 scope link valid_lft forever preferred_lft forever 3: tap0: mtu 1500 qdisc pfifo_fast state UNKNOWN qlen 500 link/ether 46:63:30:70:b5:21 brd ff:ff:ff:ff:ff:ff inet 10.2.2.2/24 brd 10.2.2.255 scope global tap0 inet6 fe80::4463:30ff:fe70:b521/64 scope link valid_lft forever preferred_lft forever user1@vm1:~$ sudo tunctl -t tap1 -u uml-net Set 'tap1' persistent and owned by uid 104 user1@vm1:~$ ip a s 1: lo: 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: mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 08:00:27:d4:45:68 brd ff:ff:ff:ff:ff:ff inet 10.0.2.15/24 brd 10.0.2.255 scope global eth0 inet6 fe80::a00:27ff:fed4:4568/64 scope link valid_lft forever preferred_lft forever 3: tap0: mtu 1500 qdisc pfifo_fast state UNKNOWN qlen 500 link/ether 46:63:30:70:b5:21 brd ff:ff:ff:ff:ff:ff inet 10.2.2.2/24 brd 10.2.2.255 scope global tap0 inet6 fe80::4463:30ff:fe70:b521/64 scope link valid_lft forever preferred_lft forever 4: tap1: mtu 1500 qdisc pfifo_fast state UNKNOWN qlen 500 link/ether 8a:ed:90:33:93:55 brd ff:ff:ff:ff:ff:ff inet 10.3.3.3/24 brd 10.3.3.255 scope global tap1 inet6 fe80::88ed:90ff:fe33:9355/64 scope link valid_lft forever preferred_lft forever user1@vm1:~$ 解释 打印当前接口配置。 编辑/etc/network/interfaces。 自动配置tap0。 为tap0设置以下 IPv4 静态参数。 将 IP 地址10.2.2.2添加给tap0。 为此 IP 地址指定网络掩码、参数“广播”和“网络”自动 从这个网络掩码导出。 指定拥有tap0接口的用户。 由于可读性的空行。 在tap1接口出现在系统中时,添加以下参数。 为tap1设置以下 IPv4 静态参数。 将 IP 地址10.3.3.3添加给tap1。 为此 IP 地址指定网络掩码。 应用网络配置更改。 打印当前接口配置。你可以看到tap0被添加到接口列表中。 添加tap1伪接口。 打印当前接口配置。你可以看到`/etc/network/interfaces中指定的参数自动应用于它。 附加题 说明如何导出“网络”和“广播”参数。 尝试这个:ping kitty。预期会失败。现在添加一个条目到/etc/hosts,以便你能够成功执行ping。

本文章首发在 LearnKu.com 网站上。



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有