Linux experiment notes txt

front

Download information

cd /home

rm -f download

rm -f teachers.ini

rm -rf course

wget --ftp-user=ftp --ftp-password=ftp --preserve-permissions ftp://47.119.161.215/*

./download zag 47.119.161.215

cd /home/course

cat linux_exam.txt | grep 3119004122

./upload 3119004122 47.119.161.215

./getScore 3119004122 47.119.161.215

global replacement
in command mode (:)
%s/replace/replace/g
example:
%s/149/36/g

sh
wget 106.55.246.243/httpN.sh
wget 106.55.246.243/ftp.sh

loopback card

Loopback network card → properties → ipv4 → properties

VMware network card

Edit → Virtual Network Editor

Virtual machine settings

33 network card
Enter administrator privileges first

su

1234
Then modify the network card configuration

vi /etc/sysconfig/network-scripts/ifcfg-ens33

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"
UUID="8972f637-4947-42cb-8150-19db760514ef"
DEVICE="ens33"
ONBOOT="yes"
IPADDR=172.28.149.1
NETMASK=255.255.255.0

Disconnect and restart ens33 to view the configuration

ifdown ens33

ifup ens33

ifconfig ens33

Test whether the network is connected under Linux

ping 172.28.149.100 -c 4

turn off firewall

Check the firewall status, active means open, inactive means close

systemctl is-active firewalld.service

Temporarily turn off the firewall

systemctl stop firewalld.service

Permanently turn off firewall (no longer starts on reboot)

systemctl disable firewalld.service

close selinux

Check the status of selinux, Enforcing means start, permissive means close

getenforce

temporarily closed

setenforce 0

change source

The default source is cn99, if the download is slow, change the source
Enter the yum source configuration directory

cd /etc/yum.repos.d

Backup the original yum source for easy recovery

mv CentOS-Base.repo CentOS-Base.repo.bk

Download the new CentOS-Base.repo to /etc/yum.repos.d/

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

Run yum makecache to generate the cache

yum clean all

yum makecache

HTTP

Install DNS

yum install -y bind

Change setting

vim /etc/named.conf

In the options field, the field value of listen-on port 53 (the first line) and allow-query (the last line) is any
Modify logging fields

logging {
        channel "default_syslog" {
                syslog daemon;
                severity info;
	};

        channel general_log {
                file "data/general_log" versions 3 size 20m;
                severity info;
                print-time yes;
                print-severity yes;
                print-category yes;
        };

        channel query_log {
                file "data/query_log" versions 3 size 20m;
                severity info;
                print-time yes;
                print-severity yes;
                print-category yes;
        };

        category general{ general_log; };
        category queries{ query_log; };
};

Add forward zone and reverse zone configuration information at the end of the file

vim /etc/named.rfc1912.zones

zone "example.com" {
	type master;
	file "data/example.com.zone";
	allow-update { none; };
};

zone "149.28.172.in-addr.arpa" {
	type master;
	file "data/172.28.149.arpa";
	allow-update { none; };
};

Forward zone file and reverse zone file

cp /var/named/named.localhost /var/named/data/example.com.zone

cp /var/named/named.localhost /var/named/data/172.28.149.arpa 

chown named.named /var/named/data/example.com.zone 

chown named.named /var/named/data/172.28.149.arpa

Modify dns forward and reverse configuration
positive

vim /var/named/data/example.com.zone

$TTL 1D
example.com. IN SOA dns.example.com. admin.example.com. (
                        0       ; serial
                        1D      ; refresh
                        1H      ; retry
                        1W      ; expire
                        3H )    ; minimum
example.com. IN NS dns.example.com.

dns          IN A  172.28.149.1
example.com. IN MX 10 mail.example.com. 
example.com. IN MX 11 mail2.example.com. 
example.com. IN MX 12 mail3.example.com. 
bbs          IN CNAME www
samba        IN A 172.28.149.1
ftp          IN A 172.28.149.1
mail         IN A 172.28.149.1
mail2        IN A 172.28.149.1
mail3        IN A 172.28.149.1
www          IN A 172.28.149.1
abc          IN A 172.28.149.203
xyz          IN A 172.28.149.203

reverse

vim /var/named/data/172.28.149.arpa

$TTL 1D
149.28.172.in-addr.arpa. IN SOA dns.example.com. admin.example.com. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
149.28.172.in-addr.arpa. IN NS dns.example.com.
1 IN PTR dns.example.com.
1 IN PTR ftp.example.com.
1 IN PTR mail.example.com.
1 IN PTR mail2.example.com.
1 IN PTR mail3.example.com.
1 IN PTR www.example.com.
1 IN PTR samba.example.com.
203 PTR abc.example.com.
    PTR xyz.example.com.

Install HTTP

yum install httpd

Change setting

vim /etc/httpd/conf/httpd.conf

modify severname
Add the following information at the end

ServerName dns.example.com:80
NameVirtualHost 172.28.149.203

<VirtualHost abc.example.com>
ServerAdmin admin@example.com
DocumentRoot "/var/www/web3" 
ServerName abc.example.com
DirectoryIndex index.html
ErrorLog logs/web3/error_log
CustomLog logs/web3/access_log common
</VirtualHost>

<VirtualHost xyz.example.com>
ServerAdmin admin@example.com
DocumentRoot "/var/www/web4" 
ServerName xyz.example.com
DirectoryIndex index.html
ErrorLog logs/web4/error_log
CustomLog logs/web4/access_log combined
</VirtualHost>

Network card settings

ifconfig ens33:3 172.28.149.203 netmask 255.255.255.0

create index

mkdir -p /var/www/web3

mkdir -p /var/www/web4

echo "hello,web3" > /var/www/web3/index.html

echo "hello,web4" > /var/www/web4/index.html

create log

mkdir -p /etc/httpd/logs/web3

mkdir -p /etc/httpd/logs/web4

touch /etc/httpd/logs/web3/error_log

touch /etc/httpd/logs/web3/access_log

touch /etc/httpd/logs/web4/error_log

touch /etc/httpd/logs/web4/access_log

test
enable dns

systemctl restart named

open http

systemctl restart httpd

Linux

yum install nscd -y

systemctl restart nscd

Open a browser and visit abc.example.com and xyz.example.com
Windows
Clear cache in cmd

ipconfig/flushdns

Open a browser and visit abc.example.com and xyz.example.com

wget abc.example.com

wget xyz.example.com

FTP

install mysql

yum install gcc gcc-c++ pam-devel

yum install mysql-devel

wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm

rpm -ivh mysql-community-release-el7-5.noarch.rpm

yum install mysql-community-server

wget http://downloads.sourceforge.net/project/pam-mysql/pam-mysql/0.7RC1/pam_mysql-0.7RC1.tar.gz

tar -zxf pam_mysql-0.7RC1.tar.gz -C /tmp/

cd /tmp/pam_mysql-0.7RC1/

./configure --with-pam=/usr --with-mysql=/usr --with-pam-mods-dir=/usr/lib64/security

make; make install

Create system users corresponding to virtual users

useradd -d /home/virtual -s /sbin/nologin virtual

chmod o+r /home/virtual

Create databases and tables to store virtual users

systemctl restart mysqld

mysql -u root -p

Note: The password here is empty by default, just press Enter to enter.

create database ftpdb;

use ftpdb;

create table ftpusers(name char(20),password char(48));

insert into ftpusers(name,password) values ('mary',password('mary'));

grant select on ftpdb.ftpusers to virtual@localhost identified by '123456';

install vsftpd

yum install vsftpd

yum install ftp

Modify vsftp main configuration file

vim /etc/vsftpd/vsftpd.conf

delete the last few sentences

pam_service_name=vsftpd

userlist_enable=YES

tcp_wrappers=YES

pam_service_name=vsftpd.virtual
guest_enable=YES
guest_username=virtual

user_config_dir=/etc/vsftpd/vsftpd_user_conf

allow_writeable_chroot=YES

Create pam authentication file

vim /etc/pam.d/vsftpd.virtual

auth required /usr/lib64/security/pam_mysql.so user=virtual passwd=123456 host=localhost db=ftpdb table=ftpusers usercolumn=name passwdcolumn=password crypt=2

account required /usr/lib64/security/pam_mysql.so user=virtual passwd=123456 host=localhost db=ftpdb table=ftpusers usercolumn=name passwdcolumn=password crypt=2

Create mary and modify properties

mkdir /home/mary

skipped by mary users

chown virtual.virtual /home/mary/

chmod 755 -R /home/mary/

mkdir -p /etc/vsftpd/vsftpd_user_conf

cd /etc/vsftpd/vsftpd_user_conf

vim mary

local_root=/home/mary
anon_other_write_enable=YES
anon_upload_enable=YES
write_enable=YES
anon_mkdir_write_enable=YES
anon_umask=022
download_enable=YES

enable log file
Find relevant information in the main configuration file /etc/vsftpd/vsftpd.conf to modify

vim /etc/vsftpd/vsftpd.conf

xferlog_std_format=NO
restart ftp

systemctl restart vsftpd

Test, account password is mary
Linux

ftp localhost

Windows
Open cmd/terminal

echo lbwnb>mary.txt 

ftp 172.28.149.1

mkdir upload

cd /upload

put mary.txt

quit

Tags: Linux

Posted by platnium on Fri, 13 May 2022 20:20:41 +0300