Set up static IP address, Samba server, and SSH service in Ubuntu

Source: Internet
Author: User
Tags nameserver ssh server

 

Set static IP addresses in Ubuntu (virtualbox)

 1. Set the network connection mode on Sun virtualbox.

Find the Ubuntu you want to set on Sun virtualbox, click Settings-> network-> Local Connection 1-> select bridged adapter as the connection method (NAT by default, this is the key to preventing mutual access ). then select your corresponding Nic under advanced, which will be automatically selected here.

 2. Set a fixed IP address and DNS on Ubuntu.

1) Open a terminal.

2) set a fixed IP Address

Enter sudo VI/etc/Network/interfaces on the terminal, which is usually displayed:

Auto Lo

Iface lo Inet loopback

Add the following content below:

Auto eth0
Iface eth0 Inet static
Address 192.168.0.120 # The fixed IP address you want to set
Gateway 192.168.0.1 # Gateway
Netmask 255.255.255.0 # Subnet Mask

Nameserver 192.168.1.1 # Network Management DNS

Note two points here. Some users do not need to modify the settings. You can use ifconfig-A on the terminal to check whether eth0 or eth1. the gateway and subnet mask are used, and the next DNS to be modified, you can enter the CMD command ipconfig-all on Windows XP to get it.

3) set DNS (this step may not be performed in virtualbox)

As mentioned above, after obtaining DNS through the command ipconfig-all in Windows XP via cmd, modify/etc/resolv. conf In ubuntu. The specific command is as follows:

Sudo VI/etc/resolv. conf

Modify the nameserver. For example, modify it to nameserver 208.96.128.88.

3. In the last step, restart the Ubuntu Nic.

Enter the restart command in the terminal, as shown below:

Sudo/etc/init. d/networking restart

 

Then, you can ping the web site of another machine on Windows XP or Ubuntu, and there will also be ssh.

 

 

Samba server construction in Ubuntu

1. Update and install

# Sudo apt-Get install Samba smbclient

2. edit/etc/samba/smb. conf to uncomment all the commented valid lines under [homes] by default.

# Sudo apt-Get install Samba smbclient

3. Add a user and password

# Sudo smbpasswd-a username

4. Start Samba and restart the system.

# Smbd

# Nmbd

OK.

 

 

Enable the SSH service in Ubuntu

There are many articles on enabling the SSH service in Ubuntu on the Internet, but most of the methods described are not ideal after testing, and remote login to Ubuntu is not possible, the reason is that the ssh-Server service is not enabled.
The final success method is as follows:

1. First install the SSH server on the server.
$ Sudo apt-Get install OpenSSH-server openssh-Client

2. Check whether sshserver is enabled.
$ PS-E | grep SSH
If only SSH-agent is available, ssh-server has not been started./etc/init. d/ssh start is required. If you see sshd, it indicates that ssh-server has been started.

3. Start ssh-server.
$/Etc/init. d/ssh restart

3. confirm that the ssh-server is working properly.
$ Netstat-TLP

Tcp6 0 0 *: SSH *: * listen-

The above output indicates that the ssh-server is already running.

4. log on to the server through SSH on the client. Assume that the IP address of the server is 192.168.1.168 and the user name for logon is Hao.
$ Ssh-l Hao 192.168.1.168

Next, you will be prompted to enter the password, and then you will be able to successfully log on to the server.

 

-------------------------------------------------------------------

The following content is for reference:

The Samba service is not installed by default in the Ubuntu server version.
1. Installation of Samba Software Package
Enter the following command in the Ubuntu terminal:
# Sudo apt-Get install samba
# Sudo apt-Get install smbclient

 

2. Start and close the Samba server
To start the Samba server, run the following command:
# Sudo/etc/init. d/samba start

 

After starting the Samba server, you can run the ps command to view the process:
# Ps-Aux

 

We can see that the samba service starts two services at the same time. smbd is mainly used to manage shared directories, and nmbd is mainly used to parse NetBIOS names. In a Windows system, a host can be added to a group, so that each host must have a name, which is used to be marked online, not the host name of the machine, it is called the NetBIOS name. The nmbd process starts as the smbd process starts.
To disable the samba service, run the following command:
#/Etc/init. d/samba stop
Or:
# Smbcontrol smbd shutdown ----------- this command only disables smbd
Restart the Samba server:
#/Etc/init. d/samba restart


3. Configure the samba Service
The main configuration file of the Samba server is/etc/samba/smb. conf, and the correspondence between NetBIOS Name and host can be written in the/etc/samba/LmHosts file.

 
(1) access the Linux shared directory without a password in Windows
Share a directory in Linux and write the setting information of the Created directory to the/etc/smb. conf file. For example, if you want to share the/home/share directory, you need to access the shared directory in windows. If the IP address of the Windows host is 192.168.0.11 and the IP address of the Linux host is 192.168.10, perform the following operations:
# Mkdir/home/share
# Vi smb. conf
Modify the content of the file as follows:
Change SECURITY = user to Security = Share
Add the following lines at the end of the file:
[Share]
Comment = This is Linux share directory
Path =/home/share
Public = Yes
Writable = Yes
Save and exit. Start the samba service:
#/Etc/init. d/samba start
The settings are complete!
Access the shared directory in windows, click Run, and enter
\ 192.168.0.10 \ share
In this way, you can access the shared directory share as an anonymous user.
The configuration file SMB. conf can be divided into two parts: the first part is global settings. The global part can configure the host information and configure whether a password is required for access. Common options include:
Workgroup = mshome
This part is the working group of Windows Hosts. Windows hosts must be in the same working group,
Server String = % H server (Samba, UBUNTU)
This option is displayed on Windows and can be customized. % H is the variable in the samba configuration file, representing the host name, that is, the host name obtained using the hostname command.
Log File =/var/log/samba/log. % m
Here, the location of the log file of the samba service is specified. % m is also the variable of the Samb. conf file, representing the NetBIOS Name of the login host. You can right-click the NetBIOS command on a Windows host to open "my computer/properties/computer instructions/changes/others.

 

Max log size = 1000
Set the maximum size of the log file to kb.
Note that "#" and ";" are comments in the smb. conf file.
The drop part in the smb. conf file is the share part. In this part, you need to add the shared directory to this file. The format and main options of this Part are as follows:
[Share] ---------- the shared file name displayed on the Windows host is not necessarily the same as the file name shared in Linux,
Comment = This is Linux share directory ---------- description of this directory
Path =/home/share ------- the real shared directory of the Linux system, which must be an absolute path
Public = Yes ------- whether to allow everyone to see this directory, no
Writable = Yes ------- whether the user is allowed to write in this directory. No is not allowed. If the user is writable, the directory must have W permissions.
Read Only = Yes -------- set whether the user is read-only
Create mode = 0700 -------- if you have the write permission, the default permission mask for the created File
Directory mode = 0755 -------- if you have the write permission, the default permission mask of the Created directory


(2) In Windows, you must enter a password to access the Linux shared directory.
In the smb. conf file, the default line is:
Security = user
This line sets the samba security level. You can set up four security registrations in Samba, from bottom to height:
Share: This option means anyone can log on without entering a password.
User: This is the default Samba level. Each user must enter a password to log on.
Server: user-level passwords are stored on the local machine, while server-level passwords and user names are stored on another host.
Domain: at this level, a Windows Domain Controller is required in the network. The verification is completed by the domain controller.
Note: As long as you enter the user name and password level, the user name must first be a user in Linux.
If you set the samba security level to the user level, you must enter a password to log on to the samba host. This user must be a user in the/etc/passwd file in Linux, SMB. the configuration of the conf file is as follows:
Add the following under security = user in the smb. conf file:
SMB passwd file =/etc/samba/smbpasswd
Add:
[Homes]
Comment = Home Directories
Valid users = % s
Here, % s is a variable that represents the username of the login user. The authenticated user can log on to his/her home directory. Then, create the smbpasswd file under/etc/samba and add it to the user:
# Touch/etc/samba/smbpasswd
# Smbpasswd-A user1
New smb password:
Retype new smb password:
This allows user1 to log on to the samba host. The format of the smbpasswd command is:
# Smbpasswd [-Option] User Name
Common options include:
-A: Add a samba user.
-D: Disable a samba user.
-E: disables Samba users.
To check the settings, run the testparm command.


(3) Access the Windows shared directory in Linux
In Linux, you can directly mount the shared directory in windows to the local machine, and then perform operations like operating files on your host. We can use the smbclient command to view the shared directory information of the specified host.
# Smbclient-l // [Target Host IP address]
After you view the shared directory in Windows, you can use the smbmount command to mount the shared directory. The smbmount command format is:
# Smbmount' \ Windows Host IP \ shared directory name' mount point-O Username
(4) access the shared directory of the Linux host in Linux
Like accessing the shared directory in windows, test the following with your own shared directory:

 

========================================================== ==============
Common samaba troubleshooting
1. Restrict invalid user access
The Administrator limits that only user1 can access the shared directory/sharedoc. During the test, it is found that user2 can also be accessed, and even all users can access it! This is an error-prone problem. Let's look at the corresponding setting segments in the samba configuration file/etc/samba/smb. conf:
[Mongodoc]
Path =/sharedoc
Valid user = user1
Writable = Yes
At first glance, there is no problem. Use the testparm tool to test it:

# Testparm

Load SMB config files from/etc/samba/smb. conf

Processing Section "[homes]"

Processing Section "[processing Doc]"

Unknown Parameter encountered: "valid user"

Ignoring unknown parameter "valid user"

.......

[Mongodoc]

Path =/sharedoc

Read Only = No

Testparm is a very useful test tool provided by Samba. In addition to displaying all the default values of Samba configuration parameters, it can also detect the actual values of parameters, compare with the value set by the Samba administrator to detect SMB. does the conf file contain any invalid parameters.

Test shows that when the shared resource is set, the parameter "Valid users" writes less "S" and becomes "valid user ", the result is that when reading the configuration file, it is detected as an unknown parameter and ignored. This parameter is invalid, which means that no valid user is set. By default, the shared directory is accessible to all users, the problem mentioned above occurs. It can be seen that if you accidentally set an error, the consequences are quite serious.

The syntax of Samba configuration options is strictly required. We recommend that you use testparm to check whether there is a syntax error to avoid this problem.

2. invalid user permission settings

Fixed the problem of User restriction, and found that "writable = yes" was clearly set to grant the write permission to user1, but user1 could not write to the shared directory on the Windows client.

Here is a conceptual issue. Although Samba grants user1 write permission on shared resources, the underlying Linux system does not allow user1 to add files or directories to shared resources. In this case, only the Linux File Permission settings of the directory can be changed before the preceding write operations can be performed. That is to say, in Linux, the user user1's permission to this directory must have an intersection with the permission granted to the user user1 in the samba service to operate this directory!

Observe the permission of the shared directory/mongodoc:

# Ls-LD/sharedoc

Drwxr-XR-x 2 root Root 4096 February 6 23:54/latest Doc

In the root directory, only root only has write operations. The root directory/mongodoc created by root naturally has the root owner and the root administrator. We can see that user1 is not a member of the root group, not the owner, others (Others), other members only have the "R-X" to read and execute, and do not have the write permission, therefore, it is useless to grant user1 write permission in Samba.

If you want to authorize user1 to perform write operations, the simplest way is to grant others the write permission to the directory:

# Chmod o + w/sharedoc

The correct solution is to add the users who set permissions to the group corresponding to the directory, authorize the group, and perform unified management.

3. Solve Chinese garbled characters

Linux shared files and directories are garbled in windows.

To solve this problem, run the locale command to check the character set of the system:

# Locale

Lang = zh_cn.gb18030

Lc_ctype = "zh_cn.gb18030"

Lc_numeric = "zh_cn.gb18030"

Lc_time = "zh_cn.gb18030"

.........

Then, according to the character set settings found by locale, modify the "[Global]" Global Parameter Setting section in the configuration file smb. conf:

(1) If locale is a zh_CN.UTF-8, add the following three rows of settings:

Displays charset = UTF-8

UNIX charset = UTF-8

DOS charset = UTF-8

(2) If locale is zh_cn.gbk, zh_cn.gb2312, or zh_cn.gb18030, add the following three rows:

Display charset = cp936

UNIX charset = cp936

DOS charset = cp936

Restart the samba service to display normal Chinese characters, whether it is from a Windows network neighbor or directly using the doscommand query.

4. How to hide files

If the hidden files starting with "." are clearly displayed when accessing the home directory, it is very dangerous to delete the important configuration files by mistake.

To prevent hidden files from being displayed, add the following settings in the [homes] section of the samba configuration file:

Veto files = /.*/

The "veto Files" parameter is used to set the file to be disabled and specifies the list of files and directories that are invisible and inaccessible. Each entry in the list must be separated by a slash (/), with an asterisk (*) and question mark (?) Wildcard characters can be used to specify multiple files and directories. Therefore, "/. */" indicates that all files starting with "." are prohibited.

You can also make other restrictions. For example, any file containing the word Windows cannot be displayed in all Samba shared directories ". for any file ending with EXE and any directory containing the word bill, you can add the following lines in the [Global] section:

Veto files =/* Windows */*. EXE/* Bill/

Note that:

(1) If you want to disable the display of hidden files and files containing newfile, you cannot use the following writing method:

Veto files = /.*/

Veto files =/* newfile */

In this way, the prohibit display of hidden files in the first line will not take effect and must be written:

Veto files =/. */* newfile */

(2) setting the "veto Files" parameter will affect Samba performance, because during file list and query, to match, samba will be forced to search and check all files and directories.

The troubleshooting method for Samba is as follows (reference ):

1. Identify the symptoms of the fault. Someone may tell you the symptoms or the first-hand symptoms you observe.

2. Because the network system is involved, determining whether the fault occurs locally or remotely may often help you make decisions, or we recommend that you perform tests first to make decisions.

3. After determining the location of the fault, we will use a set of standard tests to determine the cause of the fault, try to eliminate the symptoms, and continue until the problem is solved.

Tools for diagnosing faults between Samba and Windows customers:

Smbclient: Check that the Samba server that can be accessed and the required sharing have been defined.

Smbstatus: Check whether the water is connecting to the Samba server and what sharing is being accessed.

Nmblookup: indicates the registration name on the network.

DOS net view command: checks which shares are provided on the server from the Windows system.

DOS netstat: checks the NetBIOS Name and adapter status information.

Tcpdump: capture the network file information package and check the dialog between the Windows client and the server.

Ethereal: analyzes the information package in detail and checks for faults between Windows clients and samba.

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.