Showing posts with label FreeBSD. Show all posts
Showing posts with label FreeBSD. Show all posts

Tuesday, February 6, 2024

FreeBSD: Setting up Internet access via a proxy

Before making the settings, find out which shell is used in your Freebsd OS using the
echo "$SHELL" command.

To configure a proxy in the csh command shell (in earlier versions of the OS), follow these steps:

1. Edit the file "/.cshrc" or "/home/%username%/.cshrc" (where %username% is the user name) using the "ee" utility, adding the following lines:

setenv HTTP_PROXY login:pass@server:port
setenv FTP_PROXY login:pass@server:port
setenv http_proxy login:pass@server:port
setenv ftp_proxy login:pass@server:port

login - username for authorization on the proxy;
pass - password for authorization on the proxy;
server - FQDN or IP of the proxy server;
port - proxy server port.

If there is no authentication, the login and password can be omitted.

2. Next, add the lines to the file "/etc/make.conf":

FETCH_ENV=HTTP_PROXY=http://login:pass@server:port FETCH_ENV=FTP_PROXY=http://login:pass@server:port FETCH_ENV=http_proxy=http://login:pass@server:port FETCH_ENV=ftp_proxy=http://login:pass@server:port

If the file is missing, create it.

_______________________________________________________________________________


To configure a proxy in the sh command shell (latest OS versions):

Add the following lines to the end of the "/etc/profile" file:

export HTTP_PROXY=http://login:pass@server:port
export FTP_PROXY=http://login:pass@server:port
export http_proxy=http://login:pass@server:port
export ftp_proxy=http://login:pass@server:port


login - username for authorization on the proxy;
pass - password for authorization on the proxy;
server - FQDN or IP of the proxy server;
port - proxy server port.

If there is no authentication, the login and password can be omitted.

_______________________________________________________________________________


To apply the settings, restart the server or run: "service netif restart"
Then:
- with static IP: "service routing restart";
- with dynamic IP: "service dhclient restart em0" (where "em0" is your network interface, you can find out by running "ifconfig". This command is necessary if the IP address is distributed by a DHCP server).



Thursday, May 18, 2023

Brocade: Setting up a periodic backup of the configuration of an optical switch using the SCP protocol

To perform the task of creating periodic backups of switch configurations, we will use a host with an installed SSH server. 

Let's go through the following steps:

1. For the convenience of connecting via SSH using a script, install the "sshpass" utility.

2. Let's create a user in the server OS, which will have the rights to connect via the SCP protocol and write to the required directory of the configuration file.

3. Create a script, for example "brocade.sh", and add commands for backing up optical switches in the following form:

sshpass -p Switch_Pass ssh Switch_Address -l Switch_User configupload -all -p scp -P 22 -cra Server_Address,Server_User,config-o-rez-$(date -I).txt,Server_Pass;exit

where Switch_Address - optical switch address;
Switch_User - optical switch user;
Switch_Pass - optical switch user's password;
Server_Address - SSH server address;
Server_User - user to connect to the server via SSH;
Server_Pass - SSH server user's password.

4. Add to the task scheduler ("cron") the execution of this script with the necessary periodicity. For example, to run on the first Monday of every month at 7 am:

0 7 1-7 * 1 /path/to/brocade.sh

 

Thursday, January 5, 2023

FreeBSD: Search for packages and ports

On FreeBSD, software is usually installed in two ways: as ready-made binary packages from the repository, or compiled from the ports tree.

To search for binary packages, you can use the command "pkg search string"
or "pkg search -o string" in order to also see the category in which the port is located.

To search the ports tree, go to /usr/ports. Next, use the commands
"make search name=string" to search for complete information with dependencies,
or "make quicksearch name=string" for shortened output. Other keys can be used instead of name (path, info, www, key - replaces any key).

If the ports collection is already installed on the disk, you can use the command:
"whereis string".

Information about an already installed package can be obtained like this: "pkg info string".

Friday, September 20, 2019

FreeBSD: Downloading OS sources using SVN

First you need to install "subversion":
cd /usr/ports/devel/subversion
make install clean
rehash


Next run checkout for the desired OS branch, example for version 11:

Branch Release
svn checkout http://svn.freebsd.org/base/release/11.1.0/ /usr/src

Branch Release Engineering (branch Release with updates)
svn checkout http://svn.freebsd.org/base/releng/11.1/ /usr/src

Branch Stable
svn checkout http://svn.freebsd.org/base/stable/11/ /usr/src

Branch Currrent
svn checkout http://svn.freebsd.org/base/head/ /usr/src

If the OS does not have direct access to the Internet and only a proxy server is available, uncomment and write down the parameters "http-proxy-host", "http-proxy-port" in the section "[global]" in the configuration file "/root/.subversion/servers".

Monday, September 16, 2019

FreeBSD: Installation LAMP (Apache, PHP, MySQL, phpMyAdmin)

LAMP - comprehensive installation Apache, MySQL, PHP in OS Linux, in our case it will be
FreeBSD.

Installation order:

Apache:

cd /usr/ports/www/apache24
make install clean
rehash

In the component settings do not forget to mark items with "MySQL".
Setup web-server's autostart:
echo 'apache24_enable="YES"' >> /etc/rc.conf

And loading accf_http module for buffering HTTP connections:
echo 'accf_http_ready="YES"' >> /etc/rc.conf

Start web-server: "service apache24 start" and check the opening of the start page.

PHP:

cd /usr/ports/lang/php72
make install clean
cd /usr/ports/lang/php72-extensions
make install clean
cd /usr/ports/www/mod_php72
make install clean
rehash

When installing related packages, do not forget to specify MySQL(MySQLi) database support.

Apache & PHP setup:

Configure httpd.conf:
ee /usr/local/etc/apache24/httpd.conf

Configure parameters: ServerName (host DNS name), ServerAdmin (administrator's e-mail), DocumentRoot (location of the root directory of the site).
Uncomment "LoadModule rewrite_module libexec/apache24/mod_rewrite.so".
Change parameter "DirectoryIndex" to:"DirectoryIndex index.php index.html index.htm default.htm default.html".
Find strings:

AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz

and add after them:

AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

Save and exit "httpd.conf".

Then copy "php.ini" from template:

cp /usr/local/etc/php.ini-production /usr/local/etc/php.ini
chmod 444 /usr/local/etc/php.ini

Restart web-server: "service apache24 restart".

MySQL:

cd /usr/ports/databases/mysql80-server
make install clean
rehash

Attention! If the system says that another version of the MySQL client is already installed, then you need to uninstall it, and then continue installing the latest version of the server.
Example:

cd /usr/ports/databases/mysql56-client
make deinstall clean

Setup autostart:"echo 'mysql_enable="YES"' >> /etc/rc.conf".

MySQL setup:

Edit the configuration file if necessary: "ee /usr/local/etc/mysql/my.cnf".
Start database server: "service mysql-server start".
Run "mysqladmin -u root password 'my_password'" and setup password for user "root". By default, the password is blank, so it must be changed. Next, check the connection with the command "mysql -u root -p". If after entering the password you are in the MySQL server control line, everything works correctly. Use the "quit" command to exit back to the shell.

phpMyAdmin:

cd /usr/ports/databases/phpmyadmin
make install clean
rehash

phpMyAdmin setup:

Setup configuration file "config.inc.php":
cd /usr/local/www/phpMyAdmin
cp config.sample.inc.php config.inc.php
ee config.inc.php

Fill in the field:

$cfg['blowfish_secret'] = 'YOUR_PASS'; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */

Set secret about 32 characters. 
Save the file and proceed to configure Apache: "ee /usr/local/etc/apache24/httpd.conf":

In the "<IfModule alias_module>" section add the following line:
Alias /phpmyadmin /usr/local/www/phpMyAdmin
2. After "Directory" section add:

<Directory "/usr/local/www/phpMyAdmin">
    AllowOverride None
    Options None
    Require all granted
</Directory>


Restart web-server: "service apache24 restart" and check phpMyAdmin. You can also add parameters to allow access from specific subnets or hosts. For example:

Order Allow,Deny
Allow from 192.168.1.0/24


Additional configuration of virtual hosts (if necessary):

Let's create a directory for virtual hosts and a couple of sites for example:

mkdir /usr/local/www/vhosts
mkdir /usr/local/www/vhosts/site1.local
mkdir /usr/local/www/vhosts/site2.local


Uncomment the line in https.conf:

Include etc/apache24/extra/httpd-vhosts.conf

And add a directive:

<Directory "/usr/local/www/vhosts">
    AllowOverride None
    Options None
    Require all granted
</Directory>


Save changes and edit virtual host configuration file:
ee /usr/local/etc/apache24/extra/httpd-vhosts.conf

Delete all the contents and introduce our two hosts there as an example:

<VirtualHost *:80> 
    ServerAdmin admin@mail.com 
    DocumentRoot "/usr/local/www/vhosts/site1.local"
    ServerName
site1.local 
    ServerAlias www.site1.local 
    <Directory /usr/local/www/vhosts/site1.local>
             Order Allow,Deny
            Allow from all
 
 </Directory>
 </VirtualHost>
 <VirtualHost *:80>
     ServerAdmin admin@mail.com
    DocumentRoot "/usr/local/www/vhosts/
site2.local"
    ServerName
site2.local 
    ServerAlias www.site2.local 
    <Directory /usr/local/www/vhosts/site2.local>
             Order Allow,Deny
            Allow from all
 
 </Directory>
 </VirtualHost>

Restart Apache. Now the sites will be divided and accessible each in its own name. The necessary entries for name resolution must be configured in DNS.