1. Experimental purpose and requirements
- Understand network related concepts
- Understand various network configuration files
- Master common network related commands
- Two ways to master network configuration
- Understanding Web Services
- Master common network service configuration and application (WWW/Samba, etc.)
2. Experimental platform
The experimental environment installed in the laboratory (Linux operating system) and Touge (www.educoder.net) experimental platform (course experiment)
3. Experimental content
- Two ways to master network configuration
- Master www service installation, startup, configuration, application
- Master Samba service installation, startup, configuration, application
4. Experiment details and steps
- Refer to the PPT courseware and red hat linux 9 installation instructions.doc, VMwareTools installation and network settings, complete 2 and 3
- Eth0 network (IP/gateway/subnet mask/DNS) configuration and activation (experiment of image interface and tools (setup and netconfig)), after setting, use the ping command to test whether the network is smooth or not
- Network command practice: use of hostname/ifcofig/route/netstat/write and other commands
mission details
Web
A server generally refers to a website server, which refers to a program that resides on a certain type of computer on the Internet. It can Web
provide documents to clients such as browsers, and can also place website files for browsing by the world; it can also place data files for the world to browse. download.
The task of this level: introduce the Linux
commonly used Web
server software on the system httpd
, and we learn how to Linux
build a Web
server on the system.
related information
Currently the three most mainstream Web
servers are Httpd
, , Nginx
and IIS
.
Httpd
It is an open source software and is generally Web
used as a server. At present, the most popular Web
server software is called . It was called httpd
in the early days , and it was renamed . So sometimes hearing server and server actually mean the same thing.Http server
Apache
Http server 2.0
Httpd
Apache
Httpd
Httpd
It is the main program of Apache
the Hypertext Transfer Protocol (HTTP HTTP
) server. Designed as a stand-alone background process, it creates a pool of child processes or threads to handle requests.
Linux
The system installation software Windows
is not the same as the installation software on the system. On the Windows
Internet, we only need to download the binary file of the software to be installed (the common format is .exe
), and then double-click to install it. Linux
The common ways to install software on the system are as follows :
- Source code compilation and installation
- package installation
- Install online
The source code installation step is to download the source code to the machine, then compile the source code to generate an executable file, and then copy the generated executable file to the corresponding installation directory. The common software source code package format is, .tar.gz
etc .tar.bz2
.;
The software package installation step is to download the compiled executable file package, and then use the corresponding package management tool to install it. Different Linux
systems use different package management tools. The common package management tools are as follows:
- Ubuntu/Debian systems use the dpkg line to manage software packages (the suffix of the software package is .deb);
- The Redhat/CentOS system uses rpm to manage software packages (the suffix of the software package is .rpm);
Online installation means that the user does not need to download the corresponding software package in person, but the corresponding system needs to be able to access the Internet. Different Linux
systems use different tools to install software online. Common online software installation tools are as follows:
- Ubuntu/Debian system uses apt-get to install software online;
- Redhat/CentOS system uses yum to install software online;
It is recommended to use online installation software. The common problem of offline installation software is the dependency between software. If you install software offline, you must manually install the dependent library, while online installation only needs one command to complete all operations, and online installation will automatically To install dependent libraries;
Install Httpd from source code
Httpd
The software depends on the following 3
software packages, so Httpd
you need to install the following 3
software before installing the software.
- arp :
Apache
Portable runtime library, supports cross-platform, and its memory management module isitrans
used by the engine. - apr-util : It is
APR
a derivative version in the development package. - pcre : A
Perl
library, includingperl
compatible regular expression libraries.
The steps to install apr
dependent packages are as follows:
- Decompress the source package: tar zxvf apr-4.5.tar.gz
- Enter the source code folder: cd apr-1.4.5/
- Configuration (generate Makefile): ./configure --prefix=/usr/local/apr
- Compile the source code: make
- Install the source code: sudo make install
[Configuration successful execution result ( ./configure --prefix=/usr/local/apr
)]
[Result of successful installation]
The steps to install apr-util
dependent packages are as follows:
- Decompress the source package: tar zxvf apr-util-3.12.tar.gz
- Enter the source code folder: cd apr-util-1.3.12/
- Placement (generated Makefile): ./configure --prefix=/usr/local/apr-util -with-apr=/usr/local/apr/bin/apr-1-config
- Compile the source code: make
- Install the source code: sudo make install
[Configuration successful execution result ( ./configure --prefix=/usr/local/apr-util -with-apr=/usr/local/apr/bin/apr-1-config
)]
[Result of successful installation]
The steps to install pcre
dependent packages are as follows:
- Unzip the source package: unzip pcre-8.10.zip
- Enter the source code folder: cd pcre-8.10/
- Configuration (generate Makefile): ./configure --prefix=/usr/local/pcre
- Compile the source code: make
- Install the source code: sudo make install
[Configuration successful execution result ( ./configure --prefix=/usr/local/pcre
)]
[Result of successful installation]
Download Httpd
the source package, here is httpd-2.4.27.tar.gz .
The specific installation steps are as follows:
- Decompress the source package: tar xvfj httpd-2.4.27.tar.bz2
- Enter the source code folder: cd httpd-4.27/
- 配置(生成Makefile):./configure --prefix=/usr/local/apache --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ -with-pcre=/usr/local/pcre
- Compile the source code: make
- Install the source code: sudo make install
[Configuration successful execution result ( ./configure --prefix=/usr/local/apache --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ -with-pcre=/usr/local/pcre
)]
[Result of successful installation]
At this point, the source code installation httpd
software is over. If it is installed correctly, you can execute apachectl
the command to start the service:
Install Httpd online
The system used in this experiment environment is Ubuntu
, so use apt-get
the tool to install the software online. The specific steps are as follows:
- Update software sources: sudo apt-get update
- Install httpd: sudo apt-get install apache2
If the installation is successful, the following interface will appear:
Note: If the current user is root
, you do not need to add it when executing the above installation command sudo
.
programming requirements
The task of this level is to learn how to install Httpd
software online.
The specific programming requirements are as follows:
- Install
Httpd
software online (the experimental environment usesUbuntu
the system);
mission details
Through the study of the previous level, we learned how to Linux
install Httpd
software on the system. After we installed it, we next learned how to turn on/off Httpd
the service.
Task of this level: Introduce Linux
how to open, close and restart Httpd
the service on the system.
related information
When we install Httpd
the software successfully, the default Httpd
service is closed. At this point, if we need to access a locally built website, we must enable Httpd
the service.
The system used in this experiment environment is that Ubuntu
when we use apt-get
the online installation software, /etc/init.d/
a script to start the service software is usually generated in the directory. For example, after we use the apt-get
installation Httpd
software, we can see that /etc/init.d/
a script named apache2
Script file, the script can be used to control Httpd
the startup and shutdown of services and other information.
[ Httpd
service script file]
Linux service command
Linux
Commands are used in the system service
to control system services, which can start, stop, restart and shut down system services, and can also display the current status of all system services.
service
The usage format of the command:
service 服务名 控制命令
- Service name: the name of the service to be automatically controlled, that is,
/etc/init.d
the name of the script file in the directory; - Control commands: Control commands supported by system service scripts.
Common control commands:
- start: start the service;
- stop: close the service;
- restart: restart the service;
- status: View the service status;
Note that not all services support the above 4
control commands. Different services provide different control commands. Most services support the above 4
common control commands.
Httpd service management
When we have successfully installed Httpd
, next, we use service
the command to manage Httpd
the service.
We will introduce how to start, shut down, restart Httpd
the service, and view Httpd
the service status in the following case demonstrations.
Case presentation 1
:
To view Httpd
the service status, you can use the following command:
sudo service apache2 status
[Please experience directly in the "command line" on the right]
You can see that the current Httpd
service is in NOT running
the state, that is, closed.
Case presentation 2
:
To start Httpd
the service and check whether it starts successfully, you can use the following command:
- sudo service apache2 start
- sudo service apache2 status
[Please experience directly in the "command line" on the right]
You can see Httpd
that the service is in running
status, and the process ID
number is 4028
.
Case presentation 3
:
Restart Httpd
the service and check whether the restart is successful, you can use the following command:
- sudo service apache2 restart
- sudo service apache2 status
[Please experience directly in the "command line" on the right]
It can be seen that the current Httpd
service is restarted, and the new process ID
number has also changed 4150
.
Case presentation 4
:
To shut down Httpd
the service and check whether the shutdown is successful, you can use the following command:
- sudo service apache2 stop
- sudo service apache2 status
[Please experience directly in the "command line" on the right]
You can see Httpd
that the service is in NOT running
the state, which is closed.
Note: If the current user is root
, you don’t need to add it when executing the above command sudo
.
programming requirements
The mission of this level is to learn how to start/shut down Httpd
the server.
The specific programming requirements are as follows:
- Start
Httpd
the service (the experimental environment usesUbuntu
the system).
mission details
Through the study of the above levels, we learned to install and start Apache2
the server. Next let's learn how to configure Apache2
the server.
The task of this level: learn Apache2
the common configuration of the server.
related information
Before starting the setup Apache2
, we know that as long as we start the service, we only need to enter or Httpd
in the browser to open a default static web page, as shown in the figure below.localhost
127.0.0.1
[It is recommended that you test on a local virtual machine]
The above operation process is roughly divided into the following steps:
HTTP
To connect toIP
the server system at the above address through the protocol,80
the port is used by default (the default port is80
, there are other ports, if the default port is used, there is no need to display the input80
port) to request filesApache
in the corresponding directory of the server ;html
Apache
After the server receives the user's request, it finds and opens the corresponding file in the document directory it manageshtml
, and responds to the client browser with the content of the file;- After the browser receives
Web
the response from the server, it receives and downloadshtml
the static code on the server side, then the browser interprets the code, and finally presents the web page.
The above are the general steps for requesting a webpage. Next, let's learn how to configure Apache
the server, such as modifying the default request port.
Apache
Multiple configuration files are provided, and the content in each configuration file is different. Commonly used configuration files are as follows:
- /etc/apache2/apache2.conf: main configuration file;
- /etc/apache2/ports.conf: file for configuring ports;
- /etc/apache2/sites-enabled/000-default.conf: configure the file of the root directory of the Web document;
Apache2
Common configurations that we will cover next ;
Apache2
Configuration file introduction
/etc/apache2/apache2.conf
Yes Apache2
, the main configuration file. The configuration items stored in it are global configuration items. The common configuration items are as follows:
- Timeout: Sets the number of seconds the server waits before declaring that the request has failed. The default value is 300;
- KeepAlive: Set whether to enable HTTP persistent connection, On means open, Off means close;
- MaxKeepAliveRequests: Limits the number of requests allowed per connection when KeepAlive is enabled. If this value is set to "0", the number of requests will not be limited;
- KeepAliveTimeout: Set the number of seconds the server waits between two requests in a persistent link;
Apache2
other configuration files
/etc/apache2/ports.conf
It is Apache2
a port configuration file, which stores Apache
the listening port, and Listen
the configuration item is used to configure the listening port.
/etc/apache2/sites-enabled/000-default
It is Apache2
a configuration file used to set the virtual host directory. A simple understanding is to set the deployed website information, as shown in the figure below.
[ /etc/apache2/sites-enabled/000-default
file content]
Here are a few things we need to pay attention to:
- <VirtualHost *:80>: indicates a virtual host, where 80 indicates its access port;
- DocumentRoot: Indicates the document root directory of the virtual host, which is the directory where our web pages are stored;
- <Directory /var/www/>: Indicates some attribute configurations of the root directory;
Case presentation 1
:
By default , Apache2
the server uses 80
the port. Now we change the default port to 8080
the following steps:
- Set Listen to 8080 (sudo vim /etc/apache2/ports.conf)
- Modify <VirtualHost *:80> to <VirtualHost *:8080> (sudo vim /etc/apache2/sites-enabled/000-default)
- sudo service apache2 restart
- Open the browser and enter: localhost:8080
[edit ports.conf
file]
[edit 000-default
file]
[Use a browser to access localhost:8080
the address]
[Use a browser to access localhost
the address]
It can be seen that 80
when the port is used for access again, it cannot be accessed normally, because the port Apache2
is listening at this time 8080
.
Case presentation 2
:
Configure Apache2
to listen to two ports at the same time, one is 80
and the other is 8080
, both ports access the default static web page at the same time, the specific steps are as follows:
- Add Listen to 80 (sudo vim /etc/apache2/ports.conf)
- Add <VirtualHost *:80>(sudo vim /etc/apache2/sites-enabled/000-default), completely copy the content under the <VirtualHost *:8080> structure, and then just copy the 8080 of the copied structure Change it to 80
- sudo service apache2 restart
- Open the browser and enter: localhost:8080
- Open the browser and enter: localhost:80
[edit ports.conf
file]
[edit 000-default
file]
[Use a browser to access localhost:8080
the address]
[Use a browser to access localhost
the address]
It can be seen that the access 80
and 8080
port display results are the same at this time, indicating that Apache2
requests from these two ports are simultaneously monitored at this time.
Case presentation 3
:
Modify 80
the root directory of the website monitored by the port /var/www/html
, and modify the content of the default webpage at the same time. The specific steps are as follows:
- sudo directory /var/www/html
- sudo touch /var/www/html/index.html
- Add content to file /var/www/html/index.html: This is my first web! (sudo vim /var/www/html/index.html)
- Set <VirtualHost *:80> (sudo vim /etc/apache2/sites-enabled/000-default), modify all /var/www under the <VirtualHost *:80> structure to /var/www/html
- sudo service apache2 restart
- Open the browser and enter: localhost:80
[add content /var/www/html/index.html
]
[edit 000-default
file]
[Use a browser to access localhost
the address]
programming requirements
The mission of this level is to learn how to configure Apache2
the server.
Note: Before executing the task of this level, first execute the following command to initialize the task environment.
- mkdir /var/www/html/test
- cp /var/www/html/index.html /var/www/html/test
The specific programming requirements are as follows:
- Modify the default access port from
80
to8011
; - Add a new listening port as
8012
and set the root directory to/var/www/html/test
;
mission details
Samba
It is a free software that implements the agreement on the system Linux
and system , and is composed of a server and a client program.UNIX
SMB
The task of this level: we learn how to Linux
build a Samba
server on the system.
related information
Samba
It is a free software that implements the agreement on the system Linux
and system , and is composed of a server and a client program. ( , information service block) is a communication protocol for sharing files and printers on a local area network. It provides sharing services for resources such as files and printers among different computers in the local area network.UNIX
SMB
SMB
Server Messages Block
SMB
The protocol is a client/server type protocol that allows clients to access shared file systems, printers, and other resources on the server. Through setting, NetBIOS over TCP/IP
it Samba
can not only share resources with local area network hosts, but also share resources with computers all over the world.
Linux
The system installation software Windows
is not the same as the installation software on the system. On the Windows
Internet, we only need to download the binary file of the software to be installed (the common format is .exe
), and then double-click to install it. Linux
The common ways to install software on the system are as follows :
- Source code compilation and installation
- package installation
- Install online
The source code installation step is to download the source code to the machine, then compile the source code to generate an executable file, and then copy the generated executable file to the corresponding installation directory. The common software source code package format is, .tar.gz
etc .tar.bz2
.;
The software package installation step is to download the compiled executable file package, and then use the corresponding package management tool to install it. Different Linux
systems use different package management tools. The common package management tools are as follows:
- Ubuntu/Debian systems use dpkg to manage software packages (the suffix of the software package is .deb);
- The Redhat/CentOS system uses rpm to manage software packages (the suffix of the software package is .rpm);
Online installation means that the user does not need to download the corresponding software package in person, but the corresponding system needs to be able to access the Internet. Different Linux
systems use different tools to install software online. Common online software installation tools are as follows:
- Ubuntu/Debian system uses apt-get to install software online;
- Redhat/CentOS system uses yum to install software online;
It is recommended to use online installation software. The common problem of offline installation software is the dependency between software. If you install software offline, you must manually install the dependent library, while online installation only needs one command to complete all operations, and online installation will automatically To install dependent libraries;
Install Samba from source code
Samba
The software depends on the following software packages, so before installing Samba
the software, you need to install the following dependent packages first.
- python-dev: sudo apt-get install python-dev
- libgnutls-dev: sudo apt-get install libgnutls-dev
- libacl1-dev: sudo apt-get install libacl1-dev
- libldap2-dev: sudo apt-get install libldap2-dev
First download the source package, here is samba-4.8.2.tar.gz .
The specific installation steps are as follows:
- Decompress the source package: tar zxvf samba-4.8.2.tar.gz
- Enter the source code folder: cd samba-4.8.2/
- Placement (generated Makefile): ./configure --prefix=/usr/local/samba --without-pam
- Compile the source code: make
- Install the source code: sudo make install
[`./configure --prefix=/usr/local/samba --without-pam`successful execution
[`make` successful execution result]
[`sudo make install` successful execution result]
At this point, the source code installation Samba
software is finished. If it is installed correctly, you can execute the following command to start the service:
- sudo /usr/local/samba/sbin/smbd –D
- sudo /usr/local/samba/sbin/nmbd –D
##### Install Samba online The system used in this experiment environment is `Ubuntu`, so use the `apt-get` tool to install the software online, the specific steps are as follows:
- Update software sources: sudo apt-get update
- Install samba: sudo apt-get install samba
If the installation is successful, the following interface will appear:
Note: If the current user is root
, you do not need to add it when executing the above installation command sudo
.
programming requirements
The task of this level is to learn how to install samba
software online.
The specific programming requirements are as follows:
- Install
samba
the software online (the experimental environment usesUbuntu
the system).
mission details
Through the study of the previous level, we learned how to Linux
install samba
software on the system. After we installed it, we next learned how to turn on/off samba
the service.
Task of this level: Introduce Linux
how to open, close and restart samba
the service on the system.
related information
When we install samba
the software successfully, Ubuntu 12.04
the system default samba
service is enabled.
The system used in this experimental environment is that Ubuntu
when we use apt-get
the online installation software, /etc/init.d/
a script to start the service software is usually generated in the directory. For example, after we use apt-get
the installation samba
software, we can see that a script file /etc/init.d/
named .smbd
samba
[`samba` service script file]
##### Linux service command
Linux
Commands are used in the system service
to control system services, which can start, stop, restart and shut down system services, and can also display the current status of all system services.
service
The usage format of the command:
service 服务名 控制命令
- Service name: the name of the service to be automatically controlled, that is,
/etc/init.d
the name of the script file in the directory; - Control commands: Control commands supported by system service scripts.
Common control commands:
- start: start the service;
- stop: close the service;
- restart: restart the service;
- status: View the service status;
Note that not all services support the above 4
control commands. Different services provide different control commands. Most services support the above 4
common control commands.
samba service management
When we have successfully installed samba
, next, we use service
the command to manage samba
the service.
We will introduce how to start, shut down, restart samba
the service, and view samba
the service status in the following case demonstrations.
Case presentation 1
:
To view samba
the service status, you can use the following command:
sudo service smbd status
[Please experience directly in the "command line" on the right]
You can see that the current `samba` service is in the `running` state, that is, the running state, and the `ID` of its running process is `54244`.
Case presentation 2
:
To shut down samba
the service and check whether the shutdown is successful, you can use the following command:
- sudo service smbd stop
- sudo service smbd status
[Please experience directly in the "command line" on the right]
You can see the status samba
of the service waiting
.
Case presentation 3
:
To start samba
the service and check whether it starts successfully, you can use the following command:
- sudo service smbd start
- sudo service smbd status
[Please experience directly in the "command line" on the right]
You can see that the `samba` service is in the `running` state, and the `ID` of the running process is `54408`.
Case presentation 4
:
To restart samba
the service and check whether the restart is successful, you can use the following command:
- sudo service smbd restart
- sudo service smbd status
[Please experience directly in the "command line" on the right]
You can see that the current samba
service is blocked first stop
, and then blocked start
.
Note: If the current user is root
, you don’t need to add it when executing the above command sudo
.
programming requirements
The mission of this level is to learn how to start/shut down samba
the server.
The specific programming requirements are as follows:
- Start
samba
the service (the experimental environment usesUbuntu
the system).
mission details
Through the learning of the above levels, we have learned how to install and start samba
the server software. Next, we will learn how to use samba
the client software to log in to the server remotely.
The task of this level: learn how to use samba
the client software to log in to the server remotely.
related information
The client software is available on Linux
the system .samba
smbclient
smbclient
Commands are samba
suites that provide a command-line use for interactive access to samba
the server's shared resources. Linux
smbclient
Some frequently used commands of the command are detailed here .
smbclient
Install software online
The system used in this experiment environment is Ubuntu
, so use apt-get
the tool to install the software online. The specific steps are as follows:
- Update software sources: sudo apt-get update
- 安装smbclient:sudo apt-get install smbclient
If the installation is successful, the following interface will appear:
**Note**: If the current user is `root`, there is no need to add `sudo` when executing the above installation command.
samba
User Management
smbpasswd
Commands belong to samba
the suite, which can add or delete samba
users and change passwords for users.
smbpasswd
Command format:
smbpasswd 选项 用户名
Common options are as follows:
- -a: Add users to the smbpasswd file;
- -c: Specify the configuration file of samba;
- -x: delete the user from the smbpasswd file;
- -d: disable the specified user in the smbpasswd file;
- -e: Activate the specified user in the smbpasswd file;
- -n: empty the password of the specified user;
Username: Specify smb
the user whose password is to be changed.
Note: The user used here is an existing user in the system.
Case presentation 1
:
To add a samba
user sambaUser
, you can use the following command:
- sudo useradd sambaUser
- sudo smbpasswd -a sambaUser
[Please experience directly in the "command line" on the right]
Common usage of smbclient command
smbclient
Command format:
smbclient 选项 smb服务器
Common options are as follows:
- -L: Display all resources shared by the server;
- -p<TCP connection port>: specify the server-side TCP connection port number;
- -s<directory>: specify the directory where smb.conf is located;
- -U<user name>: specify the user name;
- -N: Do not ask for a password;
smb
Server: Specify the server to connect to smb
.
Common smbclient
commands are as follows:
- smb: \> ? or help [command] provides help about help or a command;
- smb: \> ![shell command] Execute the used SHELL command, or let the user enter the SHELL prompt;
- smb: \> cd [directory] switch to the specified directory on the server side, if not specified, smbclient returns the current local directory;
- smb: \> lcd [directory] switch to the directory specified by the client;
- smb: \> dir or ls lists the files in the current directory on the server side;
- smb: \> exit or quit to exit smbclient;
- smb: \> get file1 file2 Download file1 from the server, and store it on the local machine with the file name file2; if you don’t want to change the name, you can omit file2;
- smb: \> mget file1 file2 file3 filen Download multiple files from server;
- smb: \> md or mkdir directory to create a directory on the server;
- smb: \> rd or rmdir directory to delete a directory on the server;
- smb: \> put file1 [file2] Upload a file file1 to the server, and rename it to file2 on the server;
- smb: \> mput file1 file2 filen Upload multiple files to the server;
Note: smbclient
Many of the commands and ftp
the commands are used similarly.
Case demonstration environment initialization: perform the following operations: /etc/samba/smb.conf
append the following content to the end of the file, and restart Samba
the server. The next level explains why this is done.
- [homes]
- comment = smbclient homes
- path = /tmp
- browseable = no
- writable = yes
- create mask = 0664
- directory mask = 0775
[modified config file]
List shared folders provided by an IP address
Case presentation 1
:
Use smbclient
the client to list the shared folders provided locally (use sambaUser
the user to log in to the server, the password is fzm
), you can use the following command:
smbclient -L 127.0.0.1 -U sambaUser%fzm
[Please experience directly in the "command line" on the right]
You can see that there are 3 local shared folders, namely: print$
, IPC$
and sambaUser
.
Connect to Samba server remotely
Case presentation 2
:
Use smbclient
the client to connect to sambaUser
the shared folder (use sambaUser
the user to log in to the server, the password is fzm
), you can use the following command:
smbclient //127.0.0.1/sambaUser -U sambaUser%fzm
[Please experience directly in the "command line" on the right]
other operations
Case presentation 3
:
Display the current directory of the remote host, and display the current working directory of the client, display all file information in the current directory of the remote host, and display all information in the current working directory of the client, you can use the following commands:
- pwd
- ! pwd
- ls
- ! ls
[Please experience directly in the "command line" on the right]
Case presentation 4
:
Create a new folder on the remote host , then upload newDir
the local file to the directory, download the file on the remote host to the directory, and rename it , and finally exit the client, you can use the following command:/home/fzm/testFile
newDir
sambaUser/fzm
/home/fzm
newFzm
smbclient
- mkdir newDir
- put /home/fzm/testFile newDir/testFile
- get sambaUser/fzm /home/fzm/newFzm
- exit
[Please experience directly in the "command line" on the right]
Case presentation 5
:
To access the shared folder of the system Windows
through the server on the system , you can use the following steps:samba
Linux
Windows
Open "Run" (shortcut key ) on the host and enter the address towin+r
be accessed (format:Linux
IP
\\IP );
[Please verify on `Windows` host]
- After pressing Enter, you can see
Linux
the shared folder on the host (fzm
);
[Please verify on `Windows` host]
- Just open
fzm
the folder for access (sometimes you need to entersamba
the user name and password to access).
[Please verify on `Windows` host]
programming requirements
The task of this level is to learn how to use smbclient
commands to access samba
the shared resources of the server.
Note: Before executing the task of this level, first execute the following command to initialize the task environment.
- apt-get update
- apt-get install smbclient
- useradd testUser
- smbpasswd -a testUser (enter the newly set password)
- touch testFile
- Append the following content to the end of the file `/etc/samba/smb.conf`, and restart the `Samba` server, and restart the service
- [homes]
- comment = smbclient homes
- path = /tmp
- browseable = no
- writable = yes
- create mask = 0664
- directory mask = 0775
The specific programming requirements are as follows:
- start
samba
the service; - Use
smbclient
the command to connect to the localtestUser
shared folder (use this machine as a remote server and usetestUser
the user to access); - Create a new directory on the remote server
Dir
; - Upload a local file (
/root/testFile
) to the directory of the remote hostDir
and rename it toupLoadFile
.
mission details
Through the study of the above levels, we have learned to use smbclient
commands to log in to the remote host, and perform file upload and download operations. Next let's learn how to configure samba
the server.
The task of this level: learn samba
the common configuration of the server.
related information
In the previous level, we initialized a series of environments before the case demonstration, and now we will introduce in detail why we need to configure those environments.
samba
The server provides a lot of configuration items, and each configuration item has a different function. Next, we introduce the samba
common configuration item functions. samba
The storage path of the server configuration file is: /etc/samba/smb.conf
under the directory.
smb.conf
structure
smb.conf
The file includes 4
structures, [ Global
], [ Homes
], [ printers
], [ Userdefined_shareName
], among which:
- Globa: used to define global parameters and default values;
- Homes: shared home directory for users;
- Printers: used to define printer sharing;
- Userdefined_ShareName: Used for custom sharing (multiple available).
Global configuration parameters [Global]
The commonly used global configuration parameters are as follows:
- Workgroup: Set the workgroup to be joined by samba;
- server string: Specify the machine description in the browse list;
- netbios name: Set the NetBIOS name of samba (you need to add it yourself);
- Interface: Set the interface IP address;
- Host allow: Set the host IP that is allowed to access;
- log file: Specify the name of the log file;
- Max log size: Specify the maximum size of the log file (KB);
- security: It defines the installation level of samba.
Case presentation 1
:
Modify the machine description in the browse list to This is My Samba Server
, specifically use the following steps:
- Modify the server string value in the smb.conf file (sudo vim /etc/samba/smb.conf)
- sudo service smbd restart
- smbclient -L 127.0.0.1 -U sambaUser%fzm
[Modify configuration file]
[Please experience directly in the "command line" on the right]
Configure home sharing [homes]
home
By default, sharing will share the user's home directory, which is very dangerous. For security reasons, we need to specify the shared directory ourselves. home
The advantage of using the shared directory is that the name of the shared directory seen by different login users is their own user name.
Common properties for setting shared directories are as follows:
- comment : describe the name of the share;
- path: defines the shared directory;
- browseable : Specifies whether the shared directory can be browsed;
- Writable: Specify whether the shared directory has write permission;
- read only: Specifies that the shared directory is read-only;
- Public: Specify whether to allow Guest account access;
- Guest ok: Same as public, yes means guest access is allowed;
- create mask: the default permission to create files;
- directory mask: Default permission to create directories.
Let's now explain why we added the following properties to the configuration file in the previous level:
[Previous level configuration file]
You can see that we have home
specified the shared directory as /tmp
, and the settings can have write permissions, as well as the default permissions for creating files and directories.
Case presentation 1
:
Set home
it as browsable, specifically use the following steps:
- Modify the server string value in the smb.conf file (sudo vim /etc/samba/smb.conf)
- sudo service smbd restart
- smbclient -L 127.0.0.1 -U sambaUser%fzm
[Please experience directly in the "command line" on the right]
homes
You can see that there is now one more folder in the local shared folder .
custom share
Multiple custom shared folders can be set, the setting method home
is similar to that of , and the name of the shared folder can be chosen at will.
Case presentation 1
:
To customize a shared folder, set the shared name to MyShare
, specify the shared directory to /tmp
, and set its writable attribute and the default permissions for creating files and directories to 0644
and respectively 0755
. The specific steps are as follows:
- Modify the server string value in the smb.conf file (sudo vim /etc/samba/smb.conf)
- sudo service smbd restart
- smbclient -L 127.0.0.1 -U sambaUser%fzm
[append configuration file]
[Please experience directly in the "command line" on the right]
You can see that the newly created shared folder MyShare
is successfully displayed. If you log in, you only need to enter:smbclient //127.0.0.1/MyShare -U userName%passwd
programming requirements
The mission of this level is to learn how to configure samba
the server.
Note: Before executing the task of this level, first execute the following command to initialize the task environment.
- mkdir /testDir
- chmod 777 /testDir
- useradd testUser
- smbpasswd -a testUser (enter the newly set password)
- touch testFile
The specific programming requirements are as follows:
- Customize a shared folder, set the shared name to
TestShare
, specify the shared directory to/testDir
, and set it to be browseable, and set its writable attribute and the default permissions for creating files and directories to0644
and respectively0755
; - Use
smbclient
the command to connect to the localTestShare
shared folder (use this machine as a remote server and usetestUser
the user to access); - Create a new directory on the remote server
Dir
; - Upload a local file (
/root/testFile
) to the directory of the remote hostDir
and rename it toupLoadFile
.