Showing posts with label Network. Show all posts
Showing posts with label Network. Show all posts

Thursday, June 28, 2018

Ubuntu mount local network shared folder

Server end

  • Install Samba
    • sudo apt-get update
      sudo apt-get install samba
  • Set a password for your user in Samba
    • sudo smbpasswd -a <user_name>
      • Note: Samba uses a separate set of passwords than the standard Linux system accounts (stored in /etc/samba/smbpasswd), so you'll need to create a Samba password for yourself. This tutorial implies that you will use your own user and it does not cover situations involving other users passwords, groups, etc...
        Tip1: Use the password for your own user to facilitate.
        Tip2: Remember that your user must have permission to write and edit the folder you want to share.
        Eg.:
        sudo chown <user_name> /var/opt/blah/blahblah
        sudo chown :<user_name> /var/opt/blah/blahblah
        Tip3: If you're using another user than your own, it needs to exist in your system beforehand, you can create it without a shell access using the following command :
        sudo useradd USERNAME --shell /bin/false
        
        You can also hide the user on the login screen by adjusting lightdm's configuration, in /etc/lightdm/users.conf add the newly created user to the line :
        hidden-users=
  • Create a directory to be shared
    mkdir /home/<user_name>/<folder_name>
  • Make a safe backup copy of the original smb.conf file to your home folder, in case you make an error
    sudo cp /etc/samba/smb.conf ~
  • Edit the file "/etc/samba/smb.conf"
    sudo nano /etc/samba/smb.conf
    • Once "smb.conf" has loaded, add this to the very end of the file:
      
      [<folder_name>]
      path = /home/<user_name>/<folder_name>
      valid users = <user_name>
      read only = no
      Tip: There Should be in the spaces between the lines, and note que also there should be a single space both before and after each of the equal signs.
  • Restart the samba:
    sudo service smbd restart
  • Once Samba has restarted, use this command to check your smb.conf for any syntax errors
    testparmT

Client end

  •  access your network share
          sudo apt-get install smbclient
          # List all shares:
          smbclient -L //<HOST_IP_OR_NAME>/<folder_name> -U <user>
          # connect:
          smbclient //<HOST_IP_OR_NAME>/<folder_name> -U <user>
    To access your network share use your username (<user_name>) and password through the path "smb://<HOST_IP_OR_NAME>/<folder_name>/" (Linux users) or "\\<HOST_IP_OR_NAME>\<folder_name>\" (Windows users). Note that "<folder_name>" value is passed in "[<folder_name>]", in other words, the share name you entered in "/etc/samba/smb.conf".
    • Note: The default user group of samba is "WORKGROUP".
 2. mount 
sudo mount -o username=<> //172.29.32.184/sharename /media/Data/

for windows
sudo mount -t cifs -o username=<> //172.29.32.184/sharename /media/Data/
  • Note- If you receive the error: wrong fs type, bad option, bad superblock on... make sure you have cifs-utils installed, it may not be installed on your distro by default.
    sudo apt-get install cifs-utils

Monday, December 18, 2017

ssh login timeout but scp works

Problem:
ssh login timeout
scp and sftp work

Analysis:

scp and sftp working means port 22 works.

This was due to my router blocking TCP keepalive messages when I connected wirelessly (go figure).
Solution:
ssh my_server -o TCPKeepAlive=no 

From the documentation:
TCPKeepAlive
  Specifies whether the system should send TCP keepalive messages
  to the other side. If they are sent, death of the connection or
  crash of one of the machines will be properly noticed.  However,
  this means that connections will die if the route is down tem-
  porarily, and some people find it annoying.  On the other hand,
  if TCP keepalives are not sent, sessions may hang indefinitely on
  the server, leaving "ghost" users and consuming server resources.

  The default is "yes" (to send TCP keepalive messages), and the
  server will notice if the network goes down or the client host
  crashes.  This avoids infinitely hanging sessions.

  To disable TCP keepalive messages, the value should be set to
  "no".

Thursday, September 22, 2016

Linux (CentOS) cannot connect to the Internet

The original post is from
http://ahhafree.blogspot.hk/2013/08/linux-mint-ubuntu.html
I just adjusted it to CentOS, only wired connection is tested.

1.先變身為 root -- 在 debian 系列 (例如 ubuntu) 的版本裡, sudo bash 然後打自己的密碼
2.Linux 有沒有抓到網卡?
  (1)按 Ctrl-Alt-T 開啟終端機,輸入 ifconfig -a 如果只出現 lo 一項, 就是沒偵測到網卡。正常應該至少偵測到 lo, eth0 (有線網卡)……
In centos system "enp3s0"

  (2) 如果沒有偵測到硬體, 就無法往下做了 -- 這時請用您的 linux 版本名稱及網卡晶片名稱上網搜尋。(原來可上網,當然這部分沒問題)
3.如果有偵測到網卡, 但網路卻不通, 請下 route -n 應該要看到至少兩列數字, 類似這樣:
    Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
    192.168.3.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0
       0.0.0.0         192.168.3.254   0.0.0.0         UG    0      0        0 eth0
  (1)如果有, 表示網路其實已正常連線; 可能只是沒設定 DNS。 請跳到下一節 「設定 DNS」。
  (2)如果沒有出現上方的兩列數字, 那麼請按照您的連線環境, 挑一個方法設定連線:
      ( 結果沒有出現兩列數字)
4.有線網卡, 自動取得 ip---因為租屋的網路,所以挑這個
若您的網路環境是自動取得 ip, 請下 dhclient 網卡名稱
有些版本的指令是 dhcpd 而不是 dhclient; 總之先按 dhc 然後按一兩次 Tab 鍵, 系統會提示。
 (結果出現了 dhclient)
5.在 dhclient 後輸入 eth0 ,按 [Enter]果然網路就通了 ☺
Centos: $ sudo dhclient enp3s0

dhclient is used to get an IP address from a DHCP server.

6. If still not work
Or come out the output:
dhclient is already runing -exiting

# ifdown enp3s0
# ifup enp3s0
### RHEL/CentOS/Fedora specific command ###
# /etc/init.d/network restart

★若您有網路問題,可連結到[網路基本指令(洪朝貴教授的網頁)]查看,加以解決。本文即轉貼自此網頁。
==========
2015補充:
Ⓞ搬新家後,設定了新的光纖網路,結果筆電剛開始有線可以上網,無線都不能;過幾天連有線也不能上網了^^|||。要去設定,發現都無法設定,只好到網路上搜尋解決方法如下:

一、無線網路:
1.如上述檢查網路卡情況
2.用root權限打開 etc/network/interfaces
3.將其他各列都以#註記,只留下以下兩行:
auto lo
iface lo inet loopback