FreeBSD-12.2 网络基本设置视频教程

12 篇文章 1 订阅
11 篇文章 0 订阅

传送门

FreeBSD-12.2 系统安装视频教程

FreeBSD-12.2 网络基本设置视频教程

FreeBSD-12.2 安装xfce4桌面视频教程

FreeBSD-12.2 安装GNOME3桌面视频教程

FreeBSD-12.2 IPFW防火墙基本应用视频教程

操作录像

FreeBSD-12.2 网络基本设置视频教程

0. 开机等待时间设置

touch /boot/loader.conf
echo autoboot_delay="1" >> /boot/loader.conf

1. 网络设置

1.1. 网卡配置检查

根据【安装FreeBSD-12.2命令行版】的操作,网卡设置了使用IPv4及DCHP,但是实际发现设置了多网卡的情况下,有些网卡不能正常工作。比如,前一篇安装freebsd的文章中设置的2块网卡,网卡2生效了,可以通过nat方式上网,但是网卡1(HOST-ONLY)并未生效,无法使用主机上的ssh客户端连接进行调试。此处进行检查,并进行相关设置。

使用如下命令查看IPv4地址:

ifconfig

结果如下图:
在这里插入图片描述

可以看到网卡1,也就是em0,无IP地址。
输入如下命令,查看/etc/rc.conf内容

cat /etc/rc.conf

显示内容如下:
在这里插入图片描述

输入如下命令,在/etc/rc.conf中添加网卡1的DHCP获取

echo ifconfig_em0="DHCP" >> /etc/rc.conf

再次使用cat 命令查看rc.conf文件内容如下:
在这里插入图片描述

输入如下命令重启FREEBSD:

init 6

使用ifconfig查看网卡ip地址如下:
在这里插入图片描述
其中已经可以看到仅主机网络的ip地址了。

附上一张我本地的仅主机网络设置图如下:
在这里插入图片描述

1.2. 禁用root远程登录,并启用密码登录

使用root进行本机登录
在这里插入图片描述

使用文本编辑器vi打开sshd服务的配置。命令如下:

vi /etc/ssh/sshd_config

在vi中查找(在vi界面下,输入英文问号**?**,也就是按住shift键,再按键盘问号,在最下面弹出的提示行里,输入要查找的关键字,然后回车确定),关键字(注意大写):PermitRootLogin。截图如下:
在这里插入图片描述

查找出的匹配项,会被高亮显示,如下图
在这里插入图片描述

使用键盘的 N 键,可以查找下一处,直到找到下图所示处
在这里插入图片描述

使用键盘 H 键,将光标左移到 # 号处,单击键盘 X ,删除该行注释。见下图
在这里插入图片描述

再次查找运行使用密码进行远程登录,查找关键字(注意P大写):Password。按键盘 N 定位到#PasswordAuthentication no一行,删除注释 # 号,把no修改为yes,结果如下:
在这里插入图片描述

保存编辑内容并退出vi。输入如下命令重启ssh服务。

service sshd restart

在这里插入图片描述

使用XShell进行操作,添加主机
在这里插入图片描述

一次性接受代表仅本次运行连接,下次还会提示这个警告,我们选择“接受并保存
在这里插入图片描述

勾选记住用户名,然后输入用户名(第一部安装bsd时创建的用户):bsduser01,然后勾选记住密码,再输入密码,确定登录,如下图:
在这里插入图片描述

登录成功:
在这里插入图片描述

使用su命令,切换到root账户,以进行软件安装,系统设置等操作。

su

此处如果提示: su: Sorry 的话,就去虚拟机里面执行如下命令,然后再回来用su切换账户:

pw usermod bsduser01 -g wheel

2.软件设置

2.1.修改pkg软件源

编辑/etc/pkg/FreeBSD.conf,注释掉官方源地址,添加ustc地址,修改后内容如下:

#
# To disable this repository, instead of modifying or removing this file,
# create a /usr/local/etc/pkg/repos/FreeBSD.conf file:
#
#   mkdir -p /usr/local/etc/pkg/repos
#   echo "FreeBSD: { enabled: no }" > /usr/local/etc/pkg/repos/FreeBSD.conf
#

FreeBSD: {
#  url: "pkg+http://pkg.FreeBSD.org/${ABI}/quarterly",
  url: "pkg+http://mirrors.ustc.edu.cn/freebsd-pkg/${ABI}/quarterly",
  mirror_type: "srv",
  signature_type: "fingerprints",
  fingerprints: "/usr/share/keys/pkg",
  enabled: yes
}

2.2.安装pkg包管理器

输入命令pkg,输入y确认安装,过程如下:

root@freebsd-32:~ # pkg
The package management tool is not yet installed on your system.
Do you want to fetch and install it now? [y/N]: y
Bootstrapping pkg from pkg+http://mirrors.ustc.edu.cn/FreeBSD:12:i386/quarterly, please wait...
Verifying signature with trusted certificate pkg.freebsd.org.2013102301... done
Installing pkg-1.16.1...
Extracting pkg-1.16.1: 100%
pkg: not enough arguments
Usage: pkg [-v] [-d] [-l] [-N] [-j <jail name or id>|-c <chroot path>|-r <rootdir>] [-C <configuration file>] [-R <repo config dir>] [-o var=value] [-4|-6] <command> [<args>]

For more information on available commands and options see 'pkg help'.

更新仓库,过程如下:

root@freebsd-32:~ # pkg update
Updating FreeBSD repository catalogue...
pkg: Repository FreeBSD has a wrong packagesite, need to re-create database
Fetching meta.txz: 100%    916 B   0.9kB/s    00:01    
Fetching packagesite.txz: 100%    6 MiB   6.3MB/s    00:01    
Processing entries: 100%
FreeBSD repository update completed. 29770 packages processed.
All repositories are up to date.

2.1. 安装sudo

FreeBSD默认没有sudo,使用普通账户时多少有点麻烦,先把sudo按上

pkg install -y sudo

允许wheel组用户使用sudo命令

sed -i ".bak" 's/\# \%wheel ALL=(ALL) ALL/\%wheel ALL=(ALL) ALL/g' /usr/local/etc/sudoers

查看指定用户的所属组信息使用如下命令(请注意使用自己的普通用户名替换下面命令中的“用户名”三个字):

grep "用户名" /etc/group

效果如下图:
在这里插入图片描述

如果你的普通用户不是wheel用户(如上图所示),FreeBSD下,将用户添加到wheel用户组的命令是(请注意使用自己的普通用户名替换下面命令中的“用户名”三个字):

pw usermod 用户名 -G wheel

再次查看用户所属组信息,测试用的账户bsduser01已经属于wheel组了,如下图:
在这里插入图片描述
这样非root用户也可以方便的执行一些任务了,比如安装软件(下图所示):
在这里插入图片描述

2.2. 安装openjdk-8测试pkg包管理器运行正常

root@freebsd-32:~ # pkg install -y openjdk8
Updating FreeBSD repository catalogue...
FreeBSD repository is up to date.
All repositories are up to date.
Updating database digests format: 100%
The following 29 package(s) will be affected (of 0 checked):

New packages to be INSTALLED:
	alsa-lib: 1.1.2_2
	dejavu: 2.37_1
	expat: 2.2.10
	fontconfig: 2.13.92_2,1
	freetype2: 2.10.4
	gettext-runtime: 0.21
	giflib: 5.2.1
	indexinfo: 0.3.1
	java-zoneinfo: 2020.d
	javavmwrapper: 2.7.6
	libICE: 1.0.10,1
	libSM: 1.2.3,1
	libX11: 1.6.12,1
	libXau: 1.0.9
	libXdmcp: 1.1.3
	libXext: 1.3.4,1
	libXfixes: 5.0.3_2
	libXi: 1.7.10,1
	libXrender: 0.9.10_2
	libXt: 1.2.0,1
	libXtst: 1.2.3_2
	libfontenc: 1.1.4
	libinotify: 20180201_2
	libpthread-stubs: 0.4
	libxcb: 1.14_1
	mkfontscale: 1.2.1
	openjdk8: 8.275.01.1
	png: 1.6.37
	xorgproto: 2020.1

Number of packages to be installed: 29

The process will require 225 MiB more space.
89 MiB to be downloaded.

Proceed with this action? [y/N]: y
·····················
·····················
·····················
--
This OpenJDK implementation requires fdescfs(5) mounted on /dev/fd and
procfs(5) mounted on /proc.

If you have not done it yet, please do the following:

	mount -t fdescfs fdesc /dev/fd
	mount -t procfs proc /proc

To make it permanent, you need the following lines in /etc/fstab:

	fdesc	/dev/fd		fdescfs		rw	0	0
	proc	/proc		procfs		rw	0	0
root@freebsd-32:~ # 

编辑/etc/fstab,添加内容后如下所示:

# Device        Mountpoint      FStype  Options Dump    Pass#
/dev/ada0s1a    /               ufs     rw      1       1
/dev/ada0s1b    none            swap    sw      0       0
fdesc   /dev/fd         fdescfs         rw      0       0
proc    /proc           procfs          rw      0       0

执行命令如下命令进行自动挂载:

mount -a

添加环境变量:

echo setenv JAVA_HOME /usr/local/openjdk8 >> ~/.cshrc
echo setenv CLASSPATH .:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar >> ~/.cshrc
echo "set path = ( /sbin /bin /usr/sbin /usr/bin /usr/games /usr/local/sbin /usr/local/bin $HOME/bin /usr/local/jdk1.5.0/bin )" >> ~/.cshrc
source ~/.cshrc

执行java -version命令验证jdk安装:

root@freebsd-32:~ # java -version
openjdk version "1.8.0_275"
OpenJDK Runtime Environment (build 1.8.0_275-b01)
OpenJDK Server VM (build 25.275-b01, mixed mode)

确保javac编译器的环境变量设置正确:

root@freebsd-32:~ # javac
Usage: javac <options> <source files>
where possible options include:
  -g                         Generate all debugging info
  -g:none                    Generate no debugging info
  -g:{lines,vars,source}     Generate only some debugging info
  -nowarn                    Generate no warnings
  -verbose                   Output messages about what the compiler is doing
  -deprecation               Output source locations where deprecated APIs are used
  -classpath <path>          Specify where to find user class files and annotation processors
  -cp <path>                 Specify where to find user class files and annotation processors
  -sourcepath <path>         Specify where to find input source files
  -bootclasspath <path>      Override location of bootstrap class files
  -extdirs <dirs>            Override location of installed extensions
  -endorseddirs <dirs>       Override location of endorsed standards path
  -proc:{none,only}          Control whether annotation processing and/or compilation is done.
  -processor <class1>[,<class2>,<class3>...] Names of the annotation processors to run; bypasses default discovery process
  -processorpath <path>      Specify where to find annotation processors
  -parameters                Generate metadata for reflection on method parameters
  -d <directory>             Specify where to place generated class files
  -s <directory>             Specify where to place generated source files
  -h <directory>             Specify where to place generated native header files
  -implicit:{none,class}     Specify whether or not to generate class files for implicitly referenced files
  -encoding <encoding>       Specify character encoding used by source files
  -source <release>          Provide source compatibility with specified release
  -target <release>          Generate class files for specific VM version
  -profile <profile>         Check that API used is available in the specified profile
  -version                   Version information
  -help                      Print a synopsis of standard options
  -Akey[=value]              Options to pass to annotation processors
  -X                         Print a synopsis of nonstandard options
  -J<flag>                   Pass <flag> directly to the runtime system
  -Werror                    Terminate compilation if warnings occur
  @<filename>                Read options and filenames from file
  
root@freebsd-32:~ #

确保java的jar工具可用:

root@freebsd-32:~ # jar
Usage: jar {ctxui}[vfmn0PMe] [jar-file] [manifest-file] [entry-point] [-C dir] files ...
Options:
    -c  create new archive
    -t  list table of contents for archive
    -x  extract named (or all) files from archive
    -u  update existing archive
    -v  generate verbose output on standard output
    -f  specify archive file name
    -m  include manifest information from specified manifest file
    -n  perform Pack200 normalization after creating a new archive
    -e  specify application entry point for stand-alone application 
        bundled into an executable jar file
    -0  store only; use no ZIP compression
    -P  preserve leading '/' (absolute path) and ".." (parent directory) components from file names
    -M  do not create a manifest file for the entries
    -i  generate index information for the specified jar files
    -C  change to the specified directory and include the following file
If any file is a directory then it is processed recursively.
The manifest file name, the archive file name and the entry point name are
specified in the same order as the 'm', 'f' and 'e' flags.

Example 1: to archive two class files into an archive called classes.jar: 
       jar cvf classes.jar Foo.class Bar.class 
Example 2: use an existing manifest file 'mymanifest' and archive all the
           files in the foo/ directory into 'classes.jar': 
       jar cvfm classes.jar mymanifest -C foo/ .

root@freebsd-32:~ # 

3. 后记

安装桌面系统请查看下一篇《【CentOS已死转投FreeBSD】-【3-安装X-Window及xfce桌面】》或者喜欢GNOME桌面的请参考《【CentOS已死转投FreeBSD-12.2】-【4-安装GNOME桌面】》,两者对比各有优缺点吧,GNOME重量级吃性能一些,但是可能更美观一点;XFCE轻量级,但是美观方面稍逊一筹。

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值