Network configuration and package management
learning target
- Network Configuration
- Use
ip
/ifconfig
command to view network parametersnmcli/nmtui
Configure network connections based on the NetworkManager service usingsystem-config-network-tui
Configure a network connection based on the network service using- Modify the network configuration file directly to configure the network connection
- Disable consistent network device names
- web tool
- Network testing tools
ping
,ss
,ip route
,traceroute
,dig
- Web client tools
wget
,lftp
,elinks
/w3m
,- RPM package management
- Use
rpm
the command to query packages- Use
rpm
commands to install/uninstall/upgrade/verify packages- YUM system
- YUM and its components
- Use
yum
commands to install/uninstall/upgrade/query packagesrpm --import
Import the GPG key signature of the YUM repository using the command- Modify the warehouse configuration file to configure remote YUM warehouses (including unofficial warehouses)
- Configure a local YUM repository using the installation CD
Task 1: Using Basic Network Commands
- Display IP addresses of all devices
- Display traffic information for all connections
- show local hostname
- Display the IP on the public network gateway connected to this machine
- curl/elinks --dump
- http://whatismyip.org
- Check connectivity to 114.114.114.114
- Check the connectivity with 8.8.8.8 (send only 1 ICMP packet, and wait for 1 second response time)
- show local routing table
- Detect DNS resolution of www.baidu.com
- Specifies to use 8.8.8.8 to detect the DNS resolution of the baidu.com domain
- Display traceroute information to www.baidu.com
- Show all network socket connections
- Show all tcp type network socket connections
- Display the connection of all tcp type network sockets that the machine listens to
- Send a test email to the tony user on this machine, with the subject "test" and the content "hello)
Task 2: Configure Network Connections
- Log in to the CentOS 7 virtual machine remotely from the host machine (Windows/Mac/Linux)
- Configure connection using Host-Only NIC configured in VirtualBox
- like:
ssh [email protected]
- Modify the network connection configured on the NAT network card configured in VirtualBox
- This is equivalent to configuring the IP address of the server that can connect to the public network in the LAN of the computer room
- View the network parameters corresponding to the NAT network card
- Add 10 to the current IP address value, and keep other parameters unchanged. Use to
nmcli
reset the static network parameters for this connection - Reactivate, and detect modifications
- Check the connectivity with the public network, and check whether the domain name resolution is normal
- Reconfigure to obtain network parameters dynamically
Task 3: YUM warehouse management
- Configure domestic mirroring (method 1)
- Configure mirrors using 163 for official repositories
- Reference http://mirrors.163.com/.help/centos.html
- Install and configure EPEL repository
- Query whether the epel warehouse release package is installed on this machine
- Search the package name of the epel repository release package
- Install the EPEL repository
- Import the public key rpm signed by the GPG key of the YUM repository
--import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
- Configure domestic mirroring (method 2)
- Use
sed
the command to modify the epel warehouse configuration file configuration to use the mirror address of Tsinghua University - Tsinghua University open source mirror website: http://mirrors.tuna.tsinghua.edu.cn
- Use
- Show currently available repositories
- Create repository metadata cache locally for each repository
Tip Use the commands
yum-utils
provided in the packageyum-config-manager
to manage yum configuration options and warehouse configuration files (such as: enable/disable specified warehouses, configure warehouse configuration files from a URL, etc.)
Task 4: Install LXC
- The RPM packages related to LXC are in the EPEL warehouse, please configure the EPEL warehouse first
yum -y install debootstrap perl libvirt
systemctl is-enabled libvirtd
systemctl is-active libvirtd
systemctl start libvirtd
ip a # 显示 libvirt 创建的网桥设备
yum search lxc
yum -y install lxc lxc-templates
systemctl start lxc.service
lxc-checkconfig
yum -y install lxc-extra
echo "alias lxc-ls='lxc-ls --fancy'" >> ~/.bashrc
. ~/.bashrc
lxc-ls
Task 5: Create and use an LXC container
1. Create containers through different distribution templates
ll /usr/share/lxc/templates/
lxc-create -n c7-v1 -t centos
lxc-ls
## 在容器启动前,以 chroot 方式修改口令
chroot /var/lib/lxc/c7-v1/rootfs passwd
## 启动指定的容器,-d 表示后台
lxc-start -d -n c7-v1
## 在制定容器中直接执行命令
lxc-attach -n c7-v1 -- passwd # 在容器启动后设置口令
lxc-attach -n c7-v1 -- yum install openssh-server
lxc-attach -n c7-v1 -- systemctl start sshd
lxc-ls
ssh [<User>@]<IP>
## 关闭指定容器
lxc-stop -n c7-v1
## 创建最新版的 debian 容器
#lxc-create -n d9-v1 -t debian
## 删除容器
#lxc-destroy -n d9-v1
2. Download the template and create a container
## 0. 显示可用的镜像模版
/usr/share/lxc/templates/lxc-download -l
## 1. 从下载的镜像文件创建 CentOS6 容器
lxc-create -n c6-v1 -t download -- -d centos -r 6 -a amd64
## 后台启动容器 c6-v1
lxc-start -d -n c6-v1
## 在容器启动后,以 lxc-attach 方式修改口令
lxc-attach -n c6-v1 -- passwd
## 如果创建容器时配置了 tty,可通过如下命令连接到 tty
## 还可以加 -t <n> 表示指定使用 ttyn 终端,默认为 tty1
lxc-console -n c6-v1
## 登录后在容器中执行命令
yum install openssh-server
service sshd start
exit
#### 提示: <Ctrl-a> q 退出,返回到容器的宿主机
lxc-ls
ssh ...
## 2. 从下载的镜像文件创建 Debian 9 容器
lxc-create -n d9-v1 -t download -- -d debian -r stretch -a amd64
#lxc-create -n d8-v1 -t download -- -d debian -r jessie -a amd64
## 为 d9-v1 容器修改 PATH 环境变量
chroot /var/lib/lxc/d9-v1/rootfs
/bin/sed -i '$ i\export PATH=/bin:/sbin:$PATH' /root/.profile
source /root/.profile &> /dev/null
echo $PATH
exit
## 后台启动容器 d9-v1
lxc-start -d -n d9-v1
lxc-attach -n d9-v1 -- passwd
lxc-attach -n d9-v1 -- apt install openssh-server vim
lxc-attach -n d9-v1 -- vi ~/.bashrc
lxc-attach -n d9-v1 -- systemctl is-enabled sshd
lxc-attach -n d9-v1 -- systemctl is-active sshd
lxc-attach -n d9-v1 -- systemctl start sshd
lxc-ls
ssh ...
## 关闭指定容器
lxc-stop -n d9-v1
reference
- https://www.tecmint.com/install-create-run-lxc-linux-containers-on-centos/
- http://wiki.libvirt.org/page/VirtualNetworking
Task 6: The rpm command
- Query all RPM packages installed in the system
- Query whether the package named lxc is installed in the system
- If the package named is installed
lxc
, yes will be displayed on the screen, otherwise no will be displayed - Find out which package installed the /etc/shadow file
- Query
libvirt
package release information - Query
libvirt-daemon
package built-in pre/post configuration scripts - query
lxc
all files installed by package - Query
lxc
package dependencies - Verify
lxc
package
Task 7: The yum command
- Install the zsh package
- Use wget to download the latest usermin
- http://www.webmin.com/download/rpm/usermin-current.rpm
usermin-current
Install the .rpm downloaded to the local- Query
lxc
package release information - Query
lxc
package dependencies - When the EPEL repository is not enabled, query the dependency requirements of the lxc package
- Find out what package provides
ifconfig
andpstree
- Query all packages whose package name contains httpd
- Query all package group information
- remove
usermin
package - Remove installed via YUM transaction history
zsh
Task 8: Debian package management
- Please learn in containers on debian 9
dpkg
The use of corresponding to the rpm function- Corresponding to yum function
apt
/apt-get
rpm --import
corresponding to the functionapt-key add
Task 9: Configure CentOS 6 Network Connections
About Web Services
- static
- network - CentOS series
- networking - Debian series
- dynamic
- NetworkManager
hint
- Internet service:
network
- network interface configuration file
/etc/sysconfig/network-scripts/ifcfg-eth0
- The hostname is set in
/etc/sysconfig/network
the file- DNS resolution configuration file
/etc/resolv.conf
- The network segment of the configured static IP address should be consistent with the virtual bridge created by libvirt
1. Log in to the c6-v1 container through lxc-console or ssh
[root@c6-v1 ~]#
2. Modify the interface location file/etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
#BOOTPROTO=dhcp
BOOTPROTO=none
ONBOOT=yes
HOSTNAME=c6-v1
NM_CONTROLLED=no
TYPE=Ethernet
MTU=
#DHCP_HOSTNAME=`hostname`
IPADDR=192.168.122.161
NETMASK=255.255.255.0
GATEWAY=192.168.122.1
3. Modify the DNS resolution file/etc/resolv.conf
[root@c6-v1 ~]# echo "nameserver 192.168.122.1" > /etc/resolv.conf
4. Make sure that the network network service starts at boot time
[root@c6-v1 ~]# chkconfig network on
5. Log out of the container
[root@c6-v1 ~]# exit
If you use lxc-console to log in to the container, press <Ctrl-a> <q>
to return to the host's shell
6. Restart the network service of the c6-v1 container
[root@host ~]# lxc-attach -n c6-v1 -- /sbin/service network restart
7. Redisplay container information
[root@host ~]# lxc-ls
Task 10: Configure Debian 9 for networking
hint
- Internet service:
networking
- network interface configuration file
/etc/network/interfaces
- The hostname is set in
/etc/hostname
the file- DNS resolution configuration file
/etc/resolv.conf
- The network segment of the static IP address set should be consistent with the virtual bridge created by libvirt
1. Use the chroot command to switch to the root file system of the d9-v1 container
[root@host ~]# chroot /var/lib/lxc/d9-v1/rootfs
[root@host /]#
2. Modify the interface location file/etc/network/interfaces
[root@host /]# /bin/cat > /etc/network/interfaces <<_END
auto lo
iface lo inet loopback
auto eth0
#iface eth0 inet dhcp
iface eth0 inet static
address 192.168.122.191
netmask 255.255.255.0
gateway 192.168.122.1
_END
3. Modify the DNS resolution file/etc/resolv.conf
[root@host /]# echo "nameserver 192.168.122.1" > /etc/resolv.conf
4. Make sure the network service starts at boot time
[root@host /]# /bin/systemctl enable networking
5. Exit the container chroot
[root@host /]# exit
6. Start the container d9-v1
[root@host ~]# lxc-start -d -n d9-v1
7. Redisplay container information
[root@host ~]# lxc-ls