顯示具有 Ubuntu 標籤的文章。 顯示所有文章
顯示具有 Ubuntu 標籤的文章。 顯示所有文章

2017年5月18日 星期四

在 Ubuntu 開機時應用 NetworkManager 自動回存 iptables 設定


  1. 首先要使用 iptables-save 指令將目前的 iptables 設定儲存到某個檔案。這裡假設為 /etc/network/iptables/eth0_foxconn.ipv4.rules。
    root@cyvm:~# iptables-save > /etc/network/iptables/eth0_foxconn.ipv4.rules
    root@cyvm:~# 
    root@cyvm:~# 
  2. 在 /etc/NetworkManager/dispatcher.d/pre-up.d 底下新增一個 script。這裡假設為 iptables,完整檔案路徑即為 /etc/NetworkManager/dispatcher.d/pre-up.d/iptables。內容如下:
    #!/bin/sh
    ## $1 是網路介面名稱,如:eth0, enx00708fc27880 等等。
    ## $2 網路設定的 stage,在這裡限定此 screipt 只在 pre-up 時工作。
    
    if ! [ "$2" = "pre-up" ]; then
     echo "cylog: $0 restoring doesn't work at $2"
     exit 0
    fi
    
    case "$1" in
     "eth0")  ## 在 pre-up eth0 時怍用,網路介面並非限定 eth0,可依實際系統規畫而定。
      echo "cylog: $0 restoring iptables rules for $1"
      /sbin/iptables-restore /etc/network/iptables/eth0_foxconn.ipv4.rules
      ;;
     *)
      echo "cylog: $0 nothing to do for '$1' in '$2'"
      ;;
    esac
    
    exit 0
  3. 完成,可重開機以進行測試。

2017年5月15日 星期一

在 Ubuntu 開機時自動設置所需的內核參數

重點在於修改 /etc/sysctl.conf 檔案,修改了之後可下sysctl -p使設定立即生效。

常用的參數:


  • 路由路
    • 打開內核的封包傳遞 (IP forward) 功能:net.ipv4.ip_forward = 1

2017年2月21日 星期二

取消 Ubuntu 圖形介面,改用文字介面

修改 GRUB

  1. 修改 /etc/default/grub,將 GRUB_CMDLINE_LINUX_DEFAULT="quiet splash" 變成 GRUB_CMDLINE_LINUX_DEFAULT="text"
    # If you change this file, run 'update-grub' afterwards to update
    # /boot/grub/grub.cfg.
    # For full documentation of the options in this file, see:
    #   info -f grub -n 'Simple configuration'
    
    GRUB_DEFAULT=0
    GRUB_HIDDEN_TIMEOUT=0
    GRUB_HIDDEN_TIMEOUT_QUIET=true
    GRUB_TIMEOUT=10
    GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
    #GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
    GRUB_CMDLINE_LINUX_DEFAULT="text"
    GRUB_CMDLINE_LINUX=""
    
  2. 更新 GRUB
    root@cysrv:~# update-grub
    Generating grub configuration file ...
    Warning: Setting GRUB_TIMEOUT to a non-zero value when GRUB_HIDDEN_TIMEOUT is set is no longer supported.
    Found linux image: /boot/vmlinuz-4.4.0-63-generic
    Found initrd image: /boot/initrd.img-4.4.0-63-generic
    Found linux image: /boot/vmlinuz-4.4.0-62-generic
    Found initrd image: /boot/initrd.img-4.4.0-62-generic
    Found linux image: /boot/vmlinuz-4.4.0-59-generic
    Found initrd image: /boot/initrd.img-4.4.0-59-generic
    Found memtest86+ image: /memtest86+.elf
    Found memtest86+ image: /memtest86+.bin
    done
    


修改 systemd

  1. sudo systemctl enable multi-user.target --force
  2. sudo systemctl set-default multi-user.target

還原 GUI 設定 systemd 的方法

  1. sudo systemctl unmask lightdm
  2. sudo systemctl enable lightdm
  3. sudo systemctl set-default graphical.target

2017年1月24日 星期二

在 Ubuntu 上安裝 Samba Server

1. 安裝相關套件

sudo apt update
sudo apt upgrade
sudo apt install samba
sudo apt install libnss-winbind
其中,libnss-winbind 可讓 Linux 解析 Windows 的主機名。

2. 相關設定檔

2.1. smb.conf

/etc/samba/smb.conf

2.1.1. 一般使用者「家」目錄設定

[homes]
   comment = Home Directories
   browseable = yes
   read only  = no
   create mode    = 0600
   directory mode = 0700

2.2. nsswitch.conf

/etc/nsswitch.conf

2.2.1. 讓 Linux 解析 Windows 的主機名

hosts:          files mdns4_minimal [NOTFOUND=return] dns wins
在 hosts 後面多加一個 wins。

3. 資源管理

3.1. 新增使用者

sudo pdbedit -a -u user_name
其中,user_name為你要給定的使用者帳號名稱。
實作範例:
cy@cyvm:~$ sudo pdbedit -a -u cy
new password:
retype new password:
Unix username:        cy
NT username:
Account Flags:        [U          ]
User SID:             S-1-5-12-12345678-123456789-123456789-1234
Primary Group SID:    S-1-5-12-12345678-123456789-123456789-321
Full Name:            CY
Home Directory:       \\cyvm\cy
HomeDir Drive:
Logon Script:
Profile Path:         \\cyvm\cy\profile
Domain:               CYVM
Account desc:
Workstations:
Munged dial:
Logon time:           0
Logoff time:          三, 06  二  2036 23:06:39 CST
Kickoff time:         三, 06  二  2036 23:06:39 CST
Password last set:    二, 24  一  2017 23:46:36 CST
Password can change:  二, 24  一  2017 23:46:36 CST
Password must change: never
Last bad password   : 0
Bad password count  : 0
Logon hours         : FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF


4. 測試

4.1. 測試 smb.conf 設定是否正確

testparm
實作範例:
cy@cyvm:~$ testparm
Load smb config files from /etc/samba/smb.conf
rlimit_max: increasing rlimit_max (1024) to minimum Windows limit (16384)
WARNING: The "syslog" option is deprecated
Processing section "[homes]"
Loaded services file OK.
Server role: ROLE_STANDALONE

Press enter to see a dump of your service definitions

# Global parameters
[global]
        server string = %h server (Samba, Ubuntu)
        server role = standalone server
        map to guest = Bad User
        obey pam restrictions = Yes
        pam password change = Yes
        passwd program = /usr/bin/passwd %u
        passwd chat = *Enter\snew\s*\spassword:* %n\n *Retype\snew\s*\spassword:* %n\n *password\supdated\ssuccessfully* .
        unix password sync = Yes
        syslog = 0
        log file = /var/log/samba/log.%m
        max log size = 1000
        dns proxy = No
        usershare allow guests = Yes
        panic action = /usr/share/samba/panic-action %d
        idmap config * : backend = tdb


[homes]
        comment = Home Directories
        read only = No
        create mask = 0600
        directory mask = 0700
        directory mode = 0700


5. 服務管理

systemctl status smbd.service
systemctl restart smbd.service
systemctl enable smbd.service


2016年12月26日 星期一

[docker] 安裝 docker

Ubuntu 16.04

*請注意以下做法僅適用於 16.04 版。

  1. 安裝 docker:
    sudo apt-get update
    sudo apt-get install -y apt-transport-https ca-certificates
    sudo apt-key adv \
                   --keyserver hkp://ha.pool.sks-keyservers.net:80 \
                   --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
    echo -e "deb https://apt.dockerproject.org/repo ubuntu-xenial main"\
         | sudo tee /etc/apt/sources.list.d/docker.list
    sudo apt-get update
    sudo apt-get install -y linux-image-extra-$(uname -r) linux-image-extra-virtual
    sudo apt-get install -y docker-engine
    

  2. 啟動 docker 服務:
    sudo systemctl start docker.service
    

  3. 測試或查看 docker 狀態:
    sudo apt-cache policy docker-engine
    sudo systemctl start docker.service
    sudo docker run hello-world
    

  4. 將 docker 服務設為開機啟動:
    sudo systemctl start docker.service
    

2016年10月22日 星期六

apt 執行小技巧收集

(1) 在執行 apt-get update 出現以下訊息時該如何處理?
The following packages were automatically installed and are no longer required:
(答)
sudo apt-get autoremove


(2) 如何查詢套裝軟體資訊?
(答)
  • 簡單列示:
apt list <package_name>

  • 完整資訊:
apt show <package_name>

  • 查詢套件:


apt search <package_name_pattern>
apt-cache search <package_name_pattern>

2016年7月28日 星期四

在 Ubuntu 安裝 Oracle JDK 7/8

Oracle JDK 8

安裝套件

sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update

sudo apt-get install oracle-java8-installer


設定環境變數

sudo apt-get install oracle-java8-set-default

或者可以以下互動式指令進行設定

cykuo@cyvm:~$ sudo update-alternatives --config java
There is 1 choice for the alternative java (providing /usr/bin/java).

  Selection    Path                                     Priority   Status
------------------------------------------------------------
  0            /usr/lib/jvm/java-8-oracle/jre/bin/java   1081      auto mode
* 1            /usr/lib/jvm/java-8-oracle/jre/bin/java   1081      manual mode


Press <enter> to keep the current choice[*], or type selection number:

測試

cy@cyvm:~# java -version
java version "1.8.0_151"
Java(TM) SE Runtime Environment (build 1.8.0_151-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.151-b12, mixed mode)
cy@cyvm:~# javac -version
javac 1.8.0_151

參考


Oracle JDK 7

安裝套件

sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java7-installer


設定環境變數

sudo update-java-alternatives -s java-7-oracle
sudo apt-get install oracle-java7-set-default