index.js
async function routeSet(target, netInterface, rootPwd) {
    const connName = await searchConnNameFromNetworkInterface(netInterface);
    const prevRoutes = await searchPrevRoutes(target);
    if (prevRoutes.length == 1) {
        if (prevRoutes[0].connName === connName &&
            prevRoutes[0].target === target &&
            prevRoutes[0].gatewayIP === '0.0.0.0') {
            return; // no need to do anything
        }
    }
    await routeDelete(target, rootPwd);

    const cmds = [
        ['nmcli', 'connection', 'modify', connName,
            '+ipv4.routes', `${target} 0.0.0.0`],
        ['nmcli', 'connection', 'down', connName],
        ['nmcli', 'connection', 'up', connName],
    ];
    return await executeCommands(cmds, null, {sudo: true, password: rootPwd});
}
async function routeSet(target, netInterface, rootPwd) {
    const connName = await searchConnNameFromNetworkInterface(netInterface);
    const prevRoutes = await searchPrevRoutes(target);
    if (prevRoutes.length == 1) {
        if (prevRoutes[0].connName === connName &&
            prevRoutes[0].target === target &&
            prevRoutes[0].gatewayIP === '0.0.0.0') {
            return; // no need to do anything
        }
    }
    await routeDelete(target, rootPwd);

    const cmds = [
        ['nmcli', 'connection', 'modify', connName,
            '+ipv4.routes', `${target} 0.0.0.0`],
        ['nmcli', 'connection', 'down', connName],
        ['nmcli', 'connection', 'up', connName],
    ];
    return await executeCommands(cmds, null, {sudo: true, password: rootPwd});
}
async function routeSet ( target , netInterface , rootPwd ) { const connName = await searchConnNameFromNetworkInterface ( netInterface ) ; const prevRoutes = await searchPrevRoutes ( target ) ; if ( prevRoutes . length == 1 ) { if ( prevRoutes [ 0 ] . connName === connName && prevRoutes [ 0 ] . target === target && prevRoutes [ 0 ] . gatewayIP === '0.0.0.0' ) { return ; // no need to do anything } } await routeDelete ( target , rootPwd ) ; const cmds = [ [ 'nmcli' , 'connection' , 'modify' , connName , '+ipv4.routes' , ` ${ target } ` ] , [ 'nmcli' , 'connection' , 'down' , connName ] , [ 'nmcli' , 'connection' , 'up' , connName ] , ] ; return await executeCommands ( cmds , null , { sudo : true , password : rootPwd } ) ; }
Set static route to ipv4 network
@param {string} target : the destination network or host. e.g. 224.0.23.0/32
@param {string} netInterface : network interface to set route
@param {string} rootPwd : root password for executing sudo
@return {Promise} Return last command output
Set static route to ipv4 network